I’m trying to interface with an R package using RCall, which uses R6 classes. At the moment, I wrap the member functions with vanilla R code. Is there a nicer way I can access the functions (foo$bar()) directly? Here is my code:
@rlibrary odin
R"""
sir_ode_odin <- odin::odin({
## Derivatives
deriv(S) <- -beta*cee*S*I/N
deriv(I) <- beta*cee*S*I/N-gamma*I
deriv(R) <- gamma*I
N <- S + I + R
## Initial conditions
u[] <- user()
dim(u) <- 3
initial(S) <- u[1]
initial(I) <- u[2]
initial(R) <- u[3]
## Parameters
p[] <- user()
dim(p) <- 3
beta <- p[1]
cee <- p[2]
gamma <- p[3]
}, target="c")
sir_ode_model <- sir_ode_odin$new(user=list(u=c(990.0,10.0,0.0),
p=c(0.05,10.0,0.25)))
sir_ode_r <- function(u,p,t){
sir_ode_model$set_user(user=list(u=u,p=p))
return(sir_ode_model$deriv(t,u))
}
sir_ode_run <- function(t){
return(sir_ode_model$run(t))
}
""";