我正在使用R编程来分析FFT。现在,我想创建Java web应用程序/ java servlet,并调用R来使用Rcaller/Rcode。我有一些关于在java应用程序中调用Rcode的参考资料。例如A.csv,http://code.google.com/p/rcaller/wiki/Examples I有CSV文件
time Amplitude1 0.00000 -0.021
2 0.00001 -0.024
3 0.00003 -0.013
4 0.00004 -0.023
5 0.00005 0.019
6 0.00007 -0.002
7 0.00008 -0.013
然后我想上传这个文件,使用R Code分析FFT并绘制它。非常感谢您的帮助!先谢谢你,玛丽亚
发布于 2014-04-23 20:36:33
您将开始创建一个RCaller实例并设置Rscript.exe文件的当前安装位置。你可以从下面开始
RCaller caller = new RCaller();
Globals.detect_current_rscript();
caller.setRscriptExecutable(Globals.Rscript_current);
RCode code = new RCode();或者你可以给出确切的位置
RCaller caller = new RCaller();
caller.setRscriptExecutable("c:\\path\\to\\Rscript.exe");
RCode code = new RCode();假设您的数据保存在文件mydata.csv中。
code.addRCode("dat <- read.cvs(\"mydata.csv\", header=T, sep=\",\"");然后我们绘制振幅图
File file = code.startPlot();
code.addRCode("plot.ts(dat$Amplitude)");
code.endPlot();并将我们的代码发送到R:
caller.setRCode(code);
caller.runOnly();现在,file变量保存了图像数据。它可以使用以下代码显示在屏幕上
code.showPlot(file);要进一步阅读,请关注stdioe blog上的博客条目
发布于 2014-04-24 13:25:19
当我执行此代码时,它正在运行,但没有显示任何内容!
package test2;
import java.io.File;
import java.io.IOException;
import java.util.Random;
import javax.swing.ImageIcon;
import rcaller.RCaller;
import rcaller.RCode;
import rcaller.exception.RCallerExecutionException;
import rcaller.exception.RCallerParseException;
public class Test2 {
public static void main(String[] args) {
Test2 test2=new Test2();
}
private int span;
@SuppressWarnings("empty-statement")
public void test2()throws IOException{
try {
RCaller caller = new RCaller();
caller.setRscriptExecutable("C:\\Program Files\\R\\R-3.0.3\\bin\\Rscript.exe");
RCode code = new RCode();
code.addRCode("dat<-read.csv(\"NetBeansProjects\"test2\"A.csv\",header=T,sep=\",\"");
File file=code.startPlot();
code.addRCode("plot.ts(dat$Amplitude)");
code.endPlot();
caller.setRCode(code);
caller.runOnly();
ImageIcon i=code.getPlot(file);
code.showPlot(file);
} catch (RCallerExecutionException | RCallerParseException e) {
System.out.println(e.toString());
}
}
}https://stackoverflow.com/questions/23242185
复制相似问题