来自Java内部的R. [英] R from within Java

查看:308
本文介绍了来自Java内部的R.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Java中调用R功能的最佳方法是什么?

What's the best way to call R functionality from within Java?

我正在寻找一种快速,简单,可靠的方法,使用我的Java应用程序在R中制作标准的2d散点图和直方图。我想知道在快速谷歌搜索中出现的哪些软件包/接口最方便使用。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆