gpt4 book ai didi

java - 在 java-Rcaller 中调用 R

转载 作者:行者123 更新时间:2023-12-04 05:14:08 25 4
gpt4 key购买 nike

我正在尝试通过使用 R 调用程序在 Java 中使用 R 实现集群。我正在尝试运行用于集群验证的示例代码,但我遇到了大多数用户面临的常见错误:文件过早结束

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 ,并且您会错过许多引号,例如“分层”,....

我认为最好将您的代码放在脚本中,然后像这样从 java 调用它:

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

myScript.R 在哪里:
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 - 在 java-Rcaller 中调用 R,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14502187/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com