Created
November 20, 2010 23:32
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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