从C#.NET内部启动R图 [英] Launching an R graph from within C# .NET

查看:43
本文介绍了从C#.NET内部启动R图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C#编写控制台应用程序,我想使用R引擎在窗口中弹出图形.

I'm writing a console app in C#, and I'd like to use the R engine to pop up a graph in a window.

有人知道在Visual Studio 2012中是否可行?

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

推荐答案

要将图从R中拉到.NET中,并将其显示在WinForms面板上:

To pull a graph from R into .NET, and display it on a WinForms panel:

首先,我们必须安装Statconn,这是.NET和R之间的桥梁.安装正确的版本很重要(如果x32和x64的混合使用错误,它将不起作用).确保这一点的最简单方法是从R控制台中安装Statconn:

First, we have to install Statconn, which is the bridge between .NET and R. Its important to install the correct version (it won't work if there is the wrong mix of x32 and x64). The easiest way to ensure this is to install Statconn from within the R console:

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

在这一点上,这将导致您没有安装 Statconn 库的错误.这很容易解决:

At this point, it will give an error that you don't have the Statconn library installed. This is easy to fix:

install.packages('statconn')

这将自动安装正确的StatConn网桥版本,这是一个独立的Windows安装程序.

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

现在我们已经安装了Statconn,我们可以在 C:\ Program Files(x86)\ statconn \ DCOM \ samples \ Graphics.NET 中打开示例.NET项目.该示例.NET项目展示了如何使用R从C#WinForms项目中绘制图形.

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

p.s.还有用于Python,C ++,VBS,jscript等的其他示例代码.

p.s. There is also other sample code for Python, C++, VBS, jscript, etc.

如果无法正常运行,请尝试 R.Net ,这可能是一个更好的选择,因为Statconn已有一段时间没有更新,并且对'32位"/"64位"/受支持的R版本".

If you cannot get this working, try R.Net, which is probably a better choice because Statconn hasn't been updated in a while, and is quite picky with less than perfect mixtures of '32-bit' / '64-bit' / 'supported R versions'.

这篇关于从C#.NET内部启动R图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆