从.NET调用R(编程语言) [英] Call R (programming language) from .net
问题描述
我的工作,需要大量的stastical处理和输出作为在.NET桌面应用程序图像的应用程序。这些问题,包括产生输出图像,看起来像一个天然的适合的R http://www.r-project.org/
I'm working on an application that requires a great deal of stastical processing and output as images in a .net desktop application. The problems, including generating the output images, seem like a natural fit for R http://www.r-project.org/
是否有包装,API,SDK,或端口,让我从.NET调用R'
Is there a wrapper, API, SDK, or port that will allow me to call R from .net?
推荐答案
R.NET是pretty的越野车与R的较新版本如果它不工作的权利,它的工作原理非常(并将继续这样做,除非你确切地知道如何解决它)。
R.NET is pretty buggy with the newer version of R. And if it doesn't work right, it works terribly (and will continue to do so unless you know exactly how to fix it).
就个人而言,我建议基于R脚本文件和执行它们。 你应该做的是启动 - [R脚本
Personally, I'd recommend using R script files and executing them. What you should do is start your R script with
> sink()
> #set your working directory here with setwd()
> #your code comes in here
> sink(#name your output file here - could label it with a .txt if you please
+ )
和从.NET,则必须通过键入使用System.Diagnostics程序
,然后写code,包括System.Diagnostics命名空间:
And from .NET, you have to include the System.Diagnostics namespace by typing using System.Diagnostics
and then write this code:
string strCmdLine;
strCmdLine = "R CMD BATCH" + /* the path to your R script goes here */;
System.Diagnostics.Process.Start("CMD.exe",strCmdLine);
process1.Close();
然后就可以使用一个StreamReader这样的:
You can then use a StreamReader like this:
StreamReader ROutput = new StreamReader(/* your R output file's path should go here */)
然后分析它,请你(见正则表达式和一个字符串的拆分方法,如果你需要,太多帮助)。
And then parse it as you please (see RegEx and a string's split method if you need help with that too).
希望这有助于!
这篇关于从.NET调用R(编程语言)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!