Using the REnvironment
From Jstacs
Jump to navigationJump to search
REnvironment e = null;
try {
e = new REnvironment( server, "rserve", password );
System.out.println( "java: " + System.getProperty( "java.version" ) );
System.out.println();
System.out.println( e.getVersionInformation() );
REXP erg = e.eval( "sin(10)" );
System.out.println( erg );
System.out.println( erg.asDouble() );
e.voidEval( "a=100;" );
e.voidEval( "n = rnorm(a)" );
String plotCmd = "hist(n,breaks=a/5)";
e.plotToPDF( plotCmd, "./../test.pdf", true );
BufferedImage i = e.plot( plotCmd, 640, 480 );
REnvironment.showImage( "histogramm", i, JFrame.EXIT_ON_CLOSE );
} catch ( Exception ex ) {
ex.printStackTrace();
} finally {
if( e != null ) {
try {
e.close();
} catch ( Exception e1 ) {
System.err.println( "could not close REnvironment." );
e1.printStackTrace();
}
}
}