簡體   English   中英

無法從C#連接到R

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM