我正在尝试使用以下代码从 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 文件的引用。当我运行以下代码时,代码进入“无法找到 R 安装”的 catch 部分。有任何想法吗?有没有人有这个工作?
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)
{
}
}
}