I would like to create API with Plumber from more than one R scripts. I found documentation about mounted routers in Plumbers here. My main script looks like this:
library(plumber)
root <- plumber$new()
calculations <- plumber$new("C:/temp/R-scripts/Calculations.R")
root$mount("/calculations", calculations)
statistics <- plumber$new("C:/temp/R-scripts/Statistics.R")
root$mount("/statistics", statistics)
root$run()
If I try to call Sum function from the first file by this url: http://127.0.0.1:5787/calculations/sum?a=2&b=3 I get Internal server error and in RStudio I can see this message:
"simpleError in (function (a, b) { as.numeric(a) + as.numeric(b)})(a = "2", b = "3", a = "2", b = "3"): formal argument "a" matched by multiple actual arguments"
The first file looks like this:
#* @serializer unboxedJSON
#* @get /sum
addTwo <- function(a, b){
as.numeric(a) + as.numeric(b)
}
Any idea what I am doing wrong?
Thanks
P.S. I forgot to mention that if I change the main script to:
library(plumber)
r <- plumb("C:/temp/R-scripts/Calculations.R")
r$run()
everything works as expected