I have a C# program that generates some R code. Right now I save the script to file and then copy/paste it into the R console. I know there is a COM interface to R, but it doesn't seem to work with the latest version of R (or any version after 2.7.8). Is there some way I can just programmatically execute the R script from C# after saving it to file?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- R - Quantstart: Testing Strategy on Multiple Equit
Here is the class I recently wrote for this purpose. You can also pass in and return arguments from C# and R:
NOTE: You may want to add the following to you code, if you are interested in cleaning up the process.
proc.CloseMainWindow(); proc.Close();
Here is a simple way to achieve that,
My Rscript is located at:
R Code is at :
Our solution based on this answer on stackoverflow Call R (programming language) from .net
With monor change, we send R code from string and save it to temp file, since user run custom R code when needed.
Full blog post: http://kostylizm.blogspot.ru/2014/05/run-r-code-from-c-sharp.html
I would presume that C# has a function similar to
system()
which would allow you to call scripts running viaRscript.exe
.To do this in
C#
you'll need to useBe sure to wrap your plots like this
or image wrappers