我正在开发一个应用程序,该应用程序需要大量统计处理并将其输出为 .net 桌面应用程序中的图像.这些问题,包括生成输出图像,似乎很适合 R http://www.r-project.组织/
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/
是否有允许我从 .net 调用 R 的包装器、API、SDK 或端口?
Is there a wrapper, API, SDK, or port that will allow me to call R from .net?
R.NET 在 R.NET 的较新版本中存在相当大的问题.如果它不能正常工作,它会工作得非常糟糕(并且会继续这样做,除非你知道如何修复它).
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 脚本文件并执行它们.你应该做的是用
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 开始,您必须通过键入 using System.Diagnostics
来包含 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 */)
然后根据需要解析它(如果您也需要帮助,请参阅 RegEx 和字符串的 split 方法).
And then parse it as you please (see RegEx and a string's split method if you need help with that too).
希望这有帮助!
这篇关于从 .net 调用 R(编程语言)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!