I have a simple function in my Plumber API that looks like the following:
library(methods)
library(plumber)
# Other functions...
#' @param elist The list of events to process as a string
#' @get /process
process_events <- function(elist=""){
setClass("EventPattern", representation(sequence="character", probability="numeric", endProbs="data.frame"))
q <- new("EventPattern", sequence=elist, probability=1, endProbs=data.frame(None=0))
# Further code that should make use of q
}
I start Plumber (locally) and point it to the script containing the api (the above) as:
r <- plumb('/path/to/script/forecast.R')
r$run(port=8000, swagger = TRUE)
And call the function on the address (using PostMan):
http://localhost:8000/process?elist="abcd"
But what I end up getting is 'An Exception Occurred' with the R console saying that:
<simpleError: No method for S4 class:EventPattern>
I realize that the error suggests that a method (a generic) is required, but when I type:
q <- new("EventPattern", sequence=elist, probability=1, endProbs=data.frame(None=0))
locally on my machine (in the R console) it works fine. It suggests to me that something is not fully loaded or available to Plumber, but I have no idea how to fix it. Any ideas?