在java-Rcaller中调用R. [英] Calling R in java-Rcaller

查看:192
本文介绍了在java-Rcaller中调用R.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过使用R调用者在java中使用R来实现集群。我正在尝试运行用于群集验证的示例代码,并且我得到了大多数用户面临的常见错误:文件过早结束

I am trying to implement clustering using R in java by employing R caller. I am trying to run sample code for clustering validation and I get that common error faced by most of the users: Premature end of file

package test;
        import rcaller.RCaller;
        import java.io.File;
        import java.lang.*;
        import java.util.*;
        import java.awt.image.DataBuffer;

        public class test3 {
            public static void main(String[] args) {
                new test3();
            }
            public test3()
            {

                try{

                    RCaller caller = new RCaller();


                    caller.cleanRCode();

                    caller.setRscriptExecutable("C:/Program Files/R/R-2.15.1/bin/x64/Rscript");
                       caller.cleanRCode();

            caller.addRCode("library(clvalid)");
            caller.addRCode("data(mouse)");
            caller.addRCode("express <- mouse [,c(M1,M2,M3,NC1,NC2,NC3)]");
            caller.addRCode("rownames (express) <- mouse$ID ");
            caller.addRCode("intern <- clValid(express, 2:6 , clMethods = c( hierarchical,kmeans,diana,clara,model) ,validation = internal)");
            caller.addRCode("b <- summary(intern) ");
            caller.runAndReturnResult("b");
                }

                catch (Exception e){
                    e.printStackTrace();
                }
            }
        }


推荐答案

您的代码中存在一些拼写错误。比如 clValid 没有clvalid,你错过了许多引用,比如hierarchy,....

You have some spelling mistakes in you code. like clValid not clvalid , and you miss many quotes like "hierarchical",....

我认为它最好把你的代码放在一个脚本中,然后从java中调用它:

I think it is better to put your code in a script, and call it from java like this :

Runtime.getRuntime().exec("Rscript myScript.R"); 

其中myScript.R是:

where myScript.R is :

library(clValid)
data(mouse)
express <- mouse [,c('M1','M2','M3','NC1','NC2','NC3')]
rownames (express) <- mouse$ID 
intern <- clValid(express, 2:6 , clMethods = c( 'hierarchical','kmeans',
                                               'diana','clara','model') ,
                                                validation = 'internal')
b <- summary(intern) 

这篇关于在java-Rcaller中调用R.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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