What is the best way to build a request URL with parameters in R? Thus far I came up with this:
library(magrittr)
library(httr)
library(data.table)
url <- list(hostname = "geo.stat.fi/geoserver/vaestoalue/wfs",
scheme = "https",
query = list(service = "WFS",
version = "2.0.0",
request = "GetFeature",
typename = "vaestoalue:kunta_vaki2017",
outputFormat = "application/json")) %>%
setattr("class","url")
request <- build_url(url)
What I like about the code that I have now, is that I can easily change parameter values and rebuild the URL.
Also, the resulting url is properly html encoded:
https://geo.stat.fi/geoserver/vaestoalue/wfs/?service=WFS&version=2.0.0&request=GetFeature&typename=vaestoalue%3Akunta_vaki2017&outputFormat=application%2Fjson
But loading the data.table library, only to build an url, just doesn't feel right. Is there a better to do this?