問題描述
我正在開發(fā)一個應(yīng)用程序,該應(yīng)用程序需要大量統(tǒng)計處理并將其輸出為 .net 桌面應(yīng)用程序中的圖像.這些問題,包括生成輸出圖像,似乎很適合 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 調(diào)用 R 的包裝器、API、SDK 或端口?
Is there a wrapper, API, SDK, or port that will allow me to call R from .net?
推薦答案
R.NET 在 R.NET 的較新版本中存在相當大的問題.如果它不能正常工作,它會工作得非常糟糕(并且會繼續(xù)這樣做,除非你知道如何修復它).
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 腳本文件并執(zhí)行它們.你應(yīng)該做的是用
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 */)
然后根據(jù)需要解析它(如果您也需要幫助,請參閱 RegEx 和字符串的 split 方法).
And then parse it as you please (see RegEx and a string's split method if you need help with that too).
希望這有幫助!
這篇關(guān)于從 .net 調(diào)用 R(編程語言)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!