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? Ralf
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
Le 28/04/10 15:40, Ralf B a ?crit :> > 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? > > RalfYou can parse the String using parse and then eval the result using eval. You can do both at once using parseAndEval You can assign the String to some R variable ( say FOO) using assign, and then in R do something like : eval( parse( text = FOO ) ) Questions about JRI, rJava, REngine, etc ... usually belong to the stats-rosuda-devel mailing list: http://mailman.rz.uni-augsburg.de/mailman/listinfo/stats-rosuda-devel Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/9aKDM9 : embed images in Rd documents |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7