我正在尝试使用 C# 连接到 R。我安装了 R.Net 并在我的项目中引用了它。这是我第一次尝试 C#。任何想法我做错了什么?
这是示例 C# 代码:
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();
string dlldir = @"C:\Users\R\R-2.15.2\bin\x64";
bool r_located = false;
while (r_located == false)
{
try
{
REngine.SetDllDirectory(dlldir);
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.");
}
}
}
}
}
这是 Program.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace Form1
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}