3

JRI と rJava をうまく使っている人はいますか? R で作成したグラフやプロットを Java アプリケーションに入れたいのですが、うまくいきません。誰でも実例を提供できますか。これが私が見つけたものですが、機能していません。

import org.rosuda.JRI.REXP;
import org.rosuda.JRI.Rengine;
/**
 * @author Nero
 *In this file, I will try to plot a simple example, only to test how it?s possible to plot through java
 *Attention: Nothing will work if you have not included the JRI.jar as library ( through properties)*/

public class TryPlot {
    
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        
        //start the Rengine (JRI)
        Rengine re = new Rengine(null, false, null);
        
        //in R:  >a<- c(1.2,2.3,4.5) :
        double da[] = {1.2, 2.3, 4.5};
        long xp3 = re.rniPutDoubleArray(da);
        re.rniAssign("a", xp3, 0);
        //look up for a:
        REXP x;
        x = re.eval("a");
        System.out.println(x);
        //THE PROBLEM: The window opens, but nothing happens???
        re.eval(" plot(a)");
    }
    
}
4

1 に答える 1

2

通常の R グラフィックス デバイスは、Java やコマンドラインから起動した場合ではなく、R GUI で使用した場合にのみ機能すると思います。そこで、パッケージ「JavaGD」をグラフィックデバイスとして使用しましたが、これは正常に機能します。プロットは通常の JFrame に出力され、サブクラス化して拡張することもできます。

于 2011-03-09T09:34:38.523 に答える