Pasting list inside a URL using R -
i playing around apis , have simple question. how paste comma separated list after = in url below instead of writing manually?
library(httr) x <- get("url/?query=") in other words, given list l i'd end with:
x <- get("url/?query=a,b,c,d") thanks!
update l looks like:
> dput(l) list("a","b","c","d")
this safer , saner way build/pass query strings:
library(httr) res <- get(url = "http://httpbin.org/get", query = list( query = paste0(list("a","b","c","d"), collapse=",") )) str(content(res, as="parsed")) ## list of 4 ## $ args :list of 1 ## ..$ query: chr "a,b,c,d" ## $ headers:list of 5 ## ..$ accept : chr "application/json, text/xml, application/xml, */*" ## ..$ accept-encoding: chr "gzip, deflate" ## ..$ connection : chr "close" ## ..$ host : chr "httpbin.org" ## ..$ user-agent : chr "libcurl/7.51.0 r-curl/2.3 httr/1.2.1" ## $ origin : chr "50.252.233.22" ## $ url : chr "http://httpbin.org/get?query=a%2cb%2cc%2cd"
Comments
Post a Comment