I'm starting work on my first "real" R package and it's attempting to be a client for a website API. One problem with the API is that the allowable set of parameters to the query is not super obvious; to deal with this the API exposes endpoints that tell you the allowable set of parameters (in case they change, for example). I'd like to be able to fetch the allowable set of parameters both so the user can call a function to see what they can enter, as well as so that I can do some input checking on the actual function that sends the query.
My first thought was to provide a function something like this:
show_params <- function() {
httr::GET(url) %>%
jsonlite::fromJSON(content(.))
}
but this would call the API every time it was used. Another option I thought about was to do something like this:
params <- httr::GET(url) %>%
jsonlite::fromJSON(content(.))
show_params <- function() {
params
}
but then, as I understand it, the API would be hit when the package is attached? loaded? and I am not sure if this would be a bad idea.
I am currently not sure how to weigh having more API requests vs caching the results of a request for the rest of the package and for the user. Any thoughts?