[英]unable to connect to R from c#
我正在尝试使用以下代码从c#连接到R。 看来C#无法读取R dll文件。 我的R安装目录是这样的:
C:\Users\R-2-13\R-2.13.0\bin\i386
并且我还下载了R.NET.dll并将其放在同一目录中。 在Visual Studio中,我将引用设置为R.NET.dll文件。 当我运行以下代码时,代码进入catch部分“无法找到R安装”。 有任何想法吗? 有人有这个工作吗?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RDotNet;
namespace RNet_Calculator
{
public partial class Form1 : Form
{
// set up basics and create RDotNet instance
// if anticipated install of R is not found, ask the user to find it.
public Form1()
{
InitializeComponent();
bool r_located = false;
while (r_located == false)
{
try
{
REngine.SetDllDirectory(@"C:\Users\R-2-13\R-2.13.0\bin\i386");
REngine.CreateInstance("RDotNet");
r_located = true;
}
catch { MessageBox.Show(@"Unable to find R installation's \bin\i386 folder. Press OK to attempt to locate it.");
MessageBox.Show("error");
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
这是http://rdotnet.codeplex.com/(RDotNet ),用于开发Winform应用程序。 虽然我非常了解Shiny和所有其他类似Web的R工具,但是c#和R的组合仍然是我首选的最终用户组合。 尝试简单的操作,例如使用Shiny禁用按钮...
糟糕的rdotnet相当容易出错。 在当前版本中,即使在尝试捕获的R肽段上,它也会崩溃。
这样说:请绝对确保使用1.5版,而不是页面上愚蠢的“稳定”(=早期beta)版本。 最好通过NuGet下载它。 还要检查您是否没有将32位R与64位c#混合使用。
使用1.5的Helper-functions,初始化为:
Helper.SetEnvironmentVariables();
engine = REngine.CreateInstance(EngineName);
engine.Initialize();
# Assuming you want to catch the graphic window, use my RGraphAppHook
# on the rdotnet site http://rdotnet.codeplex.com/workitem/7
cbt = new RGraphAppHook { GraphControl = GraphPanelControl };
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.