[R] JRI API: sourcing from Java String

Duncan Murdoch murdoch.duncan at gmail.com
Wed Apr 28 16:03:53 CEST 2010


On 28/04/2010 9:40 AM, Ralf B wrote:
> Hi all,
>
> I have been using 'source(filename)' to load R code from a file
> object. However, now I have a special case where I don't have a file
> since I am loading an R script from a Jar file. I would like to avoid
> creating temporary files. Is there a way to use the 'source' command
> with a Java String? Are there any other, better ways to do that?
>   

source(x) is basically the same as eval(parse(x)) with bells and 
whistles added.  Since parse() accepts a text= argument that is an R 
character vector, you could do what you want by converting your Java 
string to an R string and calling eval and parse directly.  
Alternatively, if you need the bells and whistles, you can use 
textConnection to create a connection from an R string and source() that.

Duncan Murdoch



More information about the R-help mailing list