JavaからRを呼び出すための簡単なサンプルクラス

Javaコード:
import java.awt.Component;
import javax.swing.JFrame;
import org.rosuda.JRI.Rengine;
import org.rosuda.javaGD.GDInterface;
import org.rosuda.javaGD.JGDBufferedPanel;

public class ChangFa_Startnews24 extends GDInterface
{
JFrame f;
public void gdOpen(double w, double h)
{
if (f!=null) gdClose();
f = new JFrame(“Java知識ーー長発");

c = new JGDBufferedPanel(w, h);
f.getContentPane().add((Component) c);
f.pack();
f.setVisible(true);
}

public static void main(String args[])
{
Rengine engine = new Rengine(new String[]{ “–vanilla" }, false, null);

engine.eval(“.setenv <- if (exists(\"Sys.setenv\")) Sys.setenv else Sys.putenv");
engine.eval(“.setenv(\"JAVAGD_CLASS_NAME\"=\"ChangFa_Startnews24\")");
engine.eval(“library(JavaGD)");
engine.eval(“JavaGD()");
engine.eval(“plot(rnorm(100))");
}

}

Java

Posted by arkgame