rstudio / plumber

Turn your R code into a web API.
https://www.rplumber.io
Other
1.39k stars 256 forks source link

Can a plumbed function be defined in another file (or package?) #272

Closed MarkEdmondson1234 closed 6 years ago

MarkEdmondson1234 commented 6 years ago

I'm having some trouble getting the syntax on getting a plumbed function when that function is defined in another file.

I want to put a standard plumb function in a package. My first try was something like this:

# in the package

#' Get results for plumber
#' 
#' @param client the clientname
#' @param date The date of data to fetch
#' @param config a config file
#' 
#' @export
plumber_ga <- function(client = "none", date = Sys.Date(), config = NULL){

  message("Calling API for client:", client, " for date:", date)

  ...

}

and then trying to call that function in an API file:

# api.R

#* Get data
#* @param client the clientname
#* @param date One day of data to fetch
#* @param config A config file TBD
#* @post /datalake/<client>/foo
plumber_ga(client = "none", date = Sys.Date(), config = NULL){
  ...
}

...but when I try that, I get an client is not defined error. Is there a way to do this? I guess the annotations clash or something - or do I need to define the function only once in the api.R file?

MarkEdmondson1234 commented 6 years ago

Ok this works

#* Get  data
#* @param client the clientname
#* @param date One day of data to fetch
#* @param config A config file TBD
#* @post /datalake/<client>/google_analytics
function(client = "none", date = Sys.Date(), config = NULL){

  plumber_ga(client, date, config)

}