I need to operationalize a whole R data structure (object oriented) and its methods. Below an example to understand:
library(data.table)
myClass = setClass("myClass", contains = "data.table")
source('./DB.r')
source('./operators.R')
My structure inherits from data.table, is populated with data from the DB and has some methods overloaded, and also custom. This works fine in R-SQL Server
My problem now is to publish it as a service. As far as what i've seen in https://learn.microsoft.com/en-us/machine-learning-server/operationalize/how-to-deploy-web-service-publish-manage-in-r#standard-workflow-examples all functions have to be in the same file (other scripts cannot contain functions; they don't get published). For example, below it is mandatory that ans is assigned with the sum result so that it is returned as the service output api <- publishService( ..., inputs = list(hp = "numeric", wt = "numeric"), outputs = list(ans = "numeric"), ... )
# separate script loaded in main file
t2 <- function(a, b) { sum(a, b) }
ans <- t2(hp, wt)
but it can't be part of a function. The result will be null if it is.
So my question is: can I upload the files to the server and load them in a session and create an instance of myClass
and build the service functions on top of that? This would be to have an object in memory with all its methods and invoke them via wrapper service fuctions, so that they work in a REST way.