Question

I'm using RCaller in order to execute a R file in Java.

Basically, it looks like this:

RCaller caller = new RCaller();
RCode code = new RCode();
caller.setRscriptExecutable(PATH_TO_EXECUTABLE);
caller.cleanRCode();

code.R_source(PATH_TO_FILE);
code.addRCode("result<-test('" + param + "')");

caller.setRCode(code);
caller.runAndReturnResult("result");

... my problem is that I'm using Rcpp in this R file (PATH_TO_FILE) and it takes several seconds to compile this external C++ file in R. Therefore I want to reuse the function and not to compile this file all the time when I execute .runAndReturnResult(...).

The R file looks like this:

library(Rcpp)
sourceCpp("/cppTest.cpp")

myfunc<- test(param)
{

    t<-cppTest(4) 
    return(t)
}

Does anyone have an idea how to achieve this using RCaller or any other suggestions in case of other libraries which are capable of this?

Help is much appreciated! Thanks in advance, Chris

Was it helpful?

Solution

I don't see this as a Rcpp problem. It works as designed -- your deployment within Java may hamper you.

Reuse of R code is commonly achieved by creating a package which reliably allows you to store and reload object code. That is (among other things) what a package is for.

You essentially ask for a reinvention of sourceCpp() to also give you the benefits of a package. That won't happen. Please use a package.

And with that this then has nothing to do with the embedding inside a Java app.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top