(1)ライブラリのダウンロードとクラスパス追加
http://www.rforge.net/Rserve/files/ から、
- REngine.jar
- RserveEngine.jar
(2)サンプルコード
下記、サンプルではリモートマシンにあるRを呼び出していますが、ローカルの場合はアドレス指定なしでOKです。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REXP x ; | |
RConnection c; | |
try { | |
c = new RConnection("192.168.XX.XX"); | |
//直接コマンドで代入 | |
c.eval("x<-10"); | |
//代入はこの書き方がたぶん正解 | |
int xx=10; | |
c.assign("x",xx); | |
x = c.eval("x/2"); | |
System.out.println(x.asString()); | |
}catch (RserveException e) { | |
e.printStackTrace(); | |
} catch (REXPMismatchException e) { | |
e.printStackTrace(); | |
} |
0 件のコメント:
コメントを投稿