code snippet does not compile
Closed this issue · 1 comments
GoogleCodeExporter commented
I think some casts are needed in order to get the example java code to compile
and run, see below.
import java.io.File;
import static org.math.R.Rsession.*;
import org.math.R.Rsession;
import org.rosuda.REngine.REXPMismatchException;
public class RsessionHelper {
public static void main(String args[]) throws REXPMismatchException {
Rsession s = Rsession.newInstanceTry(System.out, null);
double[] rand = (double[]) (cast(s.eval("rnorm(10)"))); // create java variable from R command
s.set("c", Math.random()); // create R variable from java one
s.save(new File("save.Rdata"), "c"); // save variables in save.Rdata
s.rm("c"); // delete variable in R environment
s.load(new File("save.Rdata")); // load R variable from save.Rdata
s.set("df", new double[][] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }, { 10, 11, 12 } }, "x1", "x2", "x3"); // create data frame from
// given vectors
double value = (Double) (cast(s.eval("df$x1[3]"))); // access one value in data frame
s.toJPEG(new File("plot.jpg"), 400, 400, "plot(rnorm(10))"); // create jpeg file from R graphical command (like plot)
String html = s.asHTML("summary(rnorm(100))"); // format in html using R2HTML
System.out.println(html);
String txt = s.asString("summary(rnorm(100))"); // format in text
System.out.println(txt);
System.out.println(s.installPackage("sensitivity", true)); // install and load R package
System.out.println(s.installPackage("wavelets", true));
s.end();
}
}
Original issue reported on code.google.com by jens.d.n...@gmail.com
on 17 Jan 2013 at 9:42
yannrichet commented
thanks.