Java 中的 R [英] R from within Java
本文介绍了Java 中的 R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Java 中调用 R 功能的最佳方式是什么?
What's the best way to call R functionality from within Java?
我正在寻找一种快速、简单和可靠的方法来使用我的 Java 应用程序在 R 中制作标准的二维散点图和直方图.我想知道在 Google 快速搜索中出现的哪些包/接口最方便使用.
I'm looking for a quick, easy and reliable way to make standard 2d scatter plots and histograms in R using my Java applications. I was wondering which packages/interfaces that came up in a quick Google search would be most convenient to use.
期待您的建议!
推荐答案
使用 JRI:http://www.rforge.net/JRI/.它与 rJava 捆绑在一起,包括一些使用示例.
Use JRI: http://www.rforge.net/JRI/. It comes bundled with rJava, including some examples of usage.
一个非常简单的例子是这样的:
A very simple example would be like this:
import java.io.*;
import java.awt.Frame;
import java.util.Enumeration;
import org.rosuda.JRI.Rengine;
import org.rosuda.JRI.REXP;
import org.rosuda.JRI.RVector;
import org.rosuda.JRI.RMainLoopCallbacks;
public class rJavaTest {
public static void main(String[] args) {
Rengine re=new Rengine(args, false, new TextConsole());
REXP x;
re.eval("print(1:10/3)");
System.out.println(x=re.eval("iris"));
RVector v = x.asVector();
if (v.getNames()!=null) {
System.out.println("has names:");
for (Enumeration e = v.getNames().elements() ; e.hasMoreElements() ;) {
System.out.println(e.nextElement());
}
}
if (true) {
System.out.println("Now the console is yours ... have fun");
re.startMainLoop();
} else {
re.end();
System.out.println("end");
}
}
}
这篇关于Java 中的 R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文