简体   繁体   English

无法从C#连接到R

[英]unable to connect to R from c#

I am trying to connect to R from c# using the following code. 我正在尝试使用以下代码从c#连接到R。 It looks like C# is not reading the R dll files. 看来C#无法读取R dll文件。 My R installation directory is this: 我的R安装目录是这样的:

C:\Users\R-2-13\R-2.13.0\bin\i386 

and I also downloaded and put the R.NET.dll in the same directory. 并且我还下载了R.NET.dll并将其放在同一目录中。 In Visual Studio, I set the reference to R.NET.dll file. 在Visual Studio中,我将引用设置为R.NET.dll文件。 When I run the following code, the code goes the the catch section "unable to find the R Installation". 当我运行以下代码时,代码进入catch部分“无法找到R安装”。 Any ideas? 有任何想法吗? Has anybody got this working? 有人有这个工作吗?

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)
        {

        }
    }
}

This is http://rdotnet.codeplex.com/ (RDotNet) to develop Winform applications. 这是http://rdotnet.codeplex.com/(RDotNet ),用于开发Winform应用程序。 While I know Shiny and all the other Web-like R-tools quite well, the combination of c# and R still is my preferred end-user combinations. 虽然我非常了解Shiny和所有其他类似Web的R工具,但是c#和R的组合仍然是我首选的最终用户组合。 Try simple things like disabling buttons with Shiny... 尝试简单的操作,例如使用Shiny禁用按钮...

Too bad rdotnet is quite buggy; 糟糕的rdotnet相当容易出错。 in the current version, it crashes on R exeptions, even in try-catched ones. 在当前版本中,即使在尝试捕获的R肽段上,它也会崩溃。

This said: please make absolutely sure that you use version 1.5, not the stupidly called "stable" (=early beta) version on the page. 这样说:请绝对确保使用1.5版,而不是页面上愚蠢的“稳定”(=早期beta)版本。 Best download it via NuGet. 最好通过NuGet下载它。 Also check if you did not mix 32bit R with 64 bit c#. 还要检查您是否没有将32位R与64位c#混合使用。

Using the Helper-functions of 1.5, initialization is: 使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM