Running R-Graphics from C # .NET

I am writing a console application in C #, and I would like to use the R engine to display the graph in a window.

Does anyone know if this is possible from Visual Studio 2012?

+7
source share
4 answers

To display a graph from R to .NET and display it in the WinForms panel:

enter image description here

First, we need to install Statconn, which is the bridge between .NET and R. It is important to install the correct version (it will not work if there is an incorrect combination of x32 and x64). The easiest way to provide this is to install Statconn from the R console:

# Install Statconn bridge. # Load the "rcom" package: install.packages('rcom') # Load the library 'rcom': library('rcom') 

An error will be Statconn at this point if you do not have the Statconn library Statconn . This is easy to fix:

 install.packages('statconn') 

This will automatically install the correct version of the StatConn bridge, which is a standalone Windows installer.

Now that we have installed Statconn, we can open a sample .NET project in C:\Program Files (x86)\statconn\DCOM\samples\Graphics.NET . This sample .NET project shows how to use R to build graphics from a C # WinForms project.

ps There is also another code example for Python, C ++, VBS, jscript, etc.

Update

If you can't get this working, try R.Net , which is probably the best choice, because Statconn does not update after a while and is pretty picky with less advanced mixes of '32 -bit '/ '64 -bit' / 'supported version R.

+3
source

Yes it is possible. You need to execute R code with C #. When searching on google, I found the following project: Statistical language R and C # .NET: Basics from Jeff B. Cromwell .

Here is some code to generate a histogram plot of 20 common random variables:

 //using STATCONNECTORCLNTLib; StatConnector test1 = new StatConnectorClass(); test1.Init("R"); test1.Evaluate("x <- rnorm(20)"); test1.EvaluateNoReturn("hist(x)"); 
+4
source

As others say, R.net is a promising project (still unstable).

The philosophy is to manipulate R objects within a .net framework.

I think that if all you need to do is put the chart in a window, it is better to create a.bat file where you call your R script with a very good Rscript .

Something like this should work for you:

In your C # side you are calling

 Process.Start("launcher.bat"); 

and you define your launcher.bat :

 PATH PATH_TO_R/R-version/bin;%path% cd PATH_TO_R_SCRIPT Rscript myscript.R arg1 arg2 
+3
source

The R.net package can be a good place to start searching for fast google results. Alternatively, you can use a more basic approach by creating R scripts that can be invoked from the command line and using system calls from C #.

+2
source

All Articles