我正在使用 R 编程来分析 FFT 。现在我想制作 Java Web 应用程序/Java servlet 并调用 R 来使用 Rcaller/Rcode。我有一些关于在 Java 应用程序中调用 Rcode 的参考。http://code.google.com/p/rcaller/wiki/Examples
我有 CSV 文件,例如 A.csv
时间振幅
1 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 代码进行 FFT 分析和绘图。非常感谢您的帮助!在此先感谢,玛丽亚
问问题
905 次
2 回答
0
您开始创建 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();
现在,文件变量保存图像数据。它可以使用代码显示在屏幕上
code.showPlot(file);
如需进一步阅读,请关注stdioe 博客上的博客条目
于 2014-04-23T12:36:33.343 回答
0
当我执行此代码时正在运行但没有显示任何内容!!!!!!!
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());
}
}
}
于 2014-04-24T05:25:18.977 回答