Description Usage Arguments Details Value Examples
View source: R/generateQueryFunction.R
A function that generates a function to send specific API-requests and handle the returned data.
1 2 | generateQueryFunction(x, base.url, multiparam=NULL, key.param=NA,
key.object=NA, .vectorizeIt=FALSE)
|
x |
a two-column data frame containing the parameter names and values (see details). |
base.url |
a character string containing the host url of the api. |
multiparam |
a character string with the name of a parameter that can take multiple input values in the resulting function (defaults to NULL). |
key.param |
a character string containing the api key parameter required in the url. |
key.object |
the name of the object the api.key is saved in (as character). |
.vectorizeIt |
logical, indicating whether the resulting function should contain an implicit loop over parameters with no default value (i.e., allows vectors as inputs). Default is FALSE. TRUE only works if x is a data frame. |
x should contain the parameter names in the first column and respective default-values in the second column (both as character strings) Parameters that have no default value have NAs in the second column.The function attempts to get the api-key from the environment "apikeys" (therefore has to be defined there before; see saveAPIkey()).
a function
1 2 3 4 5 6 7 8 | # First, make sure the necessary API key is saved in your R session:
# (This example is based on the Project Vote Smart API [PVS API])
saveAPIkey(key.var="pvs", key="YOUR-KEY-HERE")
pvsmeasure <- "http://api.votesmart.org/Measure.getMeasure?"
measureparameters <- data.frame(parameter="measureId", value=NA)
## Not run: getMeasure <- generateOSIFunction(x=measureparameters, base.url=pvsmeasure,
key.param="key", key.object="pvs")
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.