Skip to content

Instantly share code, notes, and snippets.

@vsbuffalo
Created November 20, 2010 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vsbuffalo/708277 to your computer and use it in GitHub Desktop.
Save vsbuffalo/708277 to your computer and use it in GitHub Desktop.
An abstraction to make URLs from named R lists, rather than doing in-place string concatenation
a <- list(id=242, 'session_id'='ah876fh3', main='page.html')
makeURL <-
# Given a named list of key/values, concatenate to make a URL. The
# value of the entry with key 'main' is treated as the HTML page.
function(pieces) {
m <- which(names(pieces) == 'main')
keys.values <- paste(names(pieces[-m]), pieces[-m], collapse='&', sep='=')
return(paste(pieces[[m]], keys.values, sep='?'))
}
makeURL(a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment