REngine”不包含“SetDllDirectory”、“RDotNet”的定义

2024-03-16

My Code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using RDotNet;
using RDotNet.Devices;
using RDotNet.Internals;
using Microsoft.Win32;

namespace Con_R
{


    class Program
    {
        static void Main(string[] args)
        {
            string rhome = System.Environment.GetEnvironmentVariable("R_HOME");
            if (string.IsNullOrEmpty(rhome))
                rhome = @"C:\Program Files\R\R-3.3.1";

            System.Environment.SetEnvironmentVariable("R_HOME", rhome);
            System.Environment.SetEnvironmentVariable("PATH", System.Environment.GetEnvironmentVariable("PATH") + ";" + rhome + @"binx64");

            // Set the folder in which R.dll locates.
            //REngine.SetDllDirectory(@"C:Program FilesRR-2.12.0bini386″);
            REngine.SetDllDirectory(@"C:\Program Files\R\R-3.3.1\bin\x64");

            // REngine e = REngine.CreateInstance("test", new[] { "" });
            using (REngine engine = REngine.CreateInstance("RDotNet", new[] { "-q" }))  // quiet mode
            {

                foreach (string path in engine.EagerEvaluate(".libPaths()").AsCharacter())
                {
                    Console.WriteLine(path);
                }
                engine.Evaluate(".libPaths(C:\\Program Files\\R\\R-3.3.1\\library)");
                engine.Evaluate("source(D:\\R\\Script\\load_forecast_grid.r)");

                Console.ReadLine();
            }
        }
    }
}

出现以下错误

Error 1 'RDotNet.REngine' does not contain a definition for 'SetDllDirectory' C:\Users\Shrinith_Sanil\Documents\Visual Studio 2013\Projects\Con_R\Con_R\Program.cs 161 21 Con_R

Error 2 'RDotNet.REngine' does not contain a definition for 'CreateInstance' C:\Users\Shrinith_Sanil\Documents\Visual Studio 2013\Projects\Con_R\Con_R\Program.cs 164 45 Con_R

已添加了

Error 3 'RDotNet.REngine' does not contain a definition for 'EagerEvaluate' and no extension method 'EagerEvaluate' accepting a first argument of type 'RDotNet.REngine' could be found (are you missing a using directive or an assembly reference?) C:\Users\Shrinith_Sanil\Documents\Visual Studio 2013\Projects\Con_R\Con_R\Program.cs 167 48 Con_R


通过使用 .NET Framework 的 R.Net Collaboration 与 R 统计计算,我的 问题已解决,以下是代码中的一些修改

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using RDotNet;
using Microsoft.Win32;
using System.IO;

namespace Con_R2
{
    class Program
    {

        static string  rPath = "";
        static void Main(string[] args)
        {

            SetupPath(); // current process, soon to be deprecated
            using (REngine engine = REngine.CreateInstance("RDotNet"))
            {
                engine.Initialize(); // required since v1.5

                REngine.SetDllDirectory(rPath);

                foreach (string path in engine.Evaluate(".libPaths()").AsCharacter())
                {
                    Console.WriteLine(path);
                }
                engine.Evaluate(".libPaths(C:\\Program Files\\R\\R-3.3.1\\library)");
                //engine.Evaluate("source('c:/Program Files/R/R-3.3.1/bin/load_forecast_grid.r')");
                engine.Evaluate("source('c:/Program Files/R/R-3.3.1/bin/testcmd.r')");
                Console.ReadLine();
                Console.ReadKey();
            }          
        }

        public static void SetupPath(string Rversion = "R-3.3.1")
        {
            var oldPath = System.Environment.GetEnvironmentVariable("PATH");
            rPath = System.Environment.Is64BitProcess ?
                                   string.Format(@"C:\Program Files\R\{0}\bin\x64", Rversion) :
                                   string.Format(@"C:\Program Files\R\{0}\bin\i386", Rversion);

            if (!Directory.Exists(rPath))
                throw new DirectoryNotFoundException(
                  string.Format(" R.dll not found in : {0}", rPath));
            var newPath = string.Format("{0}{1}{2}", rPath,
                                         System.IO.Path.PathSeparator, oldPath);
            System.Environment.SetEnvironmentVariable("PATH", newPath);
        }


    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

REngine”不包含“SetDllDirectory”、“RDotNet”的定义 的相关文章

随机推荐

  • 在 Laravel 的 FormRequest 中使用复杂的条件验证规则

    我正在使用 Laravel 开发一个 Web 应用程序 我现在正在做的是创建一个 FirmRequest 来进行验证 这是我的表格请求 use Illuminate Foundation Http FormRequest class Sto
  • VS 2019 SSIS包无法添加SQL Server

    我安装了 Visual Studio 2019 和 SSIS 包扩展并创建了一个新项目 我可以毫无问题地将我的 SQL Server 添加为连接管理器 但是当我拖动Data Flow Task到包中并拖动Source Assistant对此
  • MEF 与 Mono.AddIn

    我正在开发一个 NET 3 5 C 桌面应用程序 它应该可以通过插件进行扩展 是否有任何文章等讨论 MEF 和 Mono AddIn 之间的差异来帮助我做出明智的决定 或者更好的是您有这两个框架的经验并且可以对它们发表评论吗 谢谢 帕特里克
  • geopy.exc.GeocoderInsufficientPrivileges:HTTP 错误 403:禁止

    我尝试使用 geopy 获取纬度 经度 但它会抛出 http 403 禁止错误 from geopy geocoders import Nominatim geolocator Nominatim addr 350 5th Ave New
  • 反应事件目标父节点

    是否可以获取虚拟 DOM 上事件目标的父节点 在我的基本 React 组件中 我有一个从 onClick 事件触发的方法 我想获取父虚拟 DOM 节点属性 handleClick e The following code only give
  • 用浮点数初始化 NSArray?

    这是用浮点对象初始化 NSArray 的有效方法吗 NSArray fatArray NSArray arrayWithObjects NSNumber numberWithFloat 6 9 NSNumber numberWithFloa
  • Ruby on Rails:有哪些可用的报告和/或图表工具? [关闭]

    Closed 此问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 我刚刚开始使用 Ruby Rails 想知道 Rails 开发人员使用什么在 Rails 站点上提供报告
  • 结束对话 C# 机器人

    我正在用 C 构建一个聊天机器人 我希望在一些消息之后对话停止 但我不知道该怎么做 我已经设置了消息限制 并且我希望在达到此限制后不能再发送消息 有我的代码 private int NombreDeMessages protected ov
  • 是否有通用 I2C 命令来查看设备是否仍然存在于总线上?

    是否有通用的 I2C 命令来查看设备在初始化一次后是否仍然存在于总线上 例如 OLED 显示器 我问这个的原因是为了避免主程序由于库代码中存在无限循环而冻结 当设备断开连接时 例如 Wire 库 在 MCU 启动时 我想检查设备是否可用 并
  • python3请求使用quote而不是quote_plus

    我使用 Python 3 和requests http docs python requests org en master 用于查询 REST 服务的模块 库 看来请求默认使用urllib parse quote plus 对于 urle
  • 在后台接收蓝牙管理器通知

    我在我的应用程序中使用BluetoothManager私有框架 我想知道当应用程序处于后台时如何接收BluetoothManager通知 例如 在后台接收连接 断开连接的蓝牙通知 提前致谢 Use global notification e
  • 在 GridView 中通过分页维护排序

    我目前正在尝试编写代码 以便在更改 GridView 上的页面时保持排序首选项 我当前的代码运行良好 可以根据用户的排序选择对数据进行排序 但是当换页时 排序不起作用 我没有收到错误 而是收到未排序的结果 这是我的 aspx 代码
  • 如何使用sequelize 与postgres 进行日期比较

    我想删除日期在 20 分钟之前的所有记录 Postgres 或 Sequelize 对裸露的 javascript 不满意Date我提供的对象作为比较值 我在 postgres 9 6 数据库之上使用sequelize 4 37 有问题的列
  • Flask AttributeError:“HTMLString”对象没有属性“__call__”

    我创建了一个宏来处理表单错误 如下所示 macro render field with errors field p field label field kwargs safe if field errors p ul for error
  • R:如何将移动平均值应用于数据框中的列子集?

    我有一个数据框 training set 其中包含 83 个变量的 150 个观察值 我想用一些移动平均线来转换其中 82 个列 问题是结果最终只有 150 个数值 即 1 列 如何在数据中的每一列中单独应用移动平均函数并保持第 83 列不
  • “您的设备与此版本不兼容”

    我在 Play 商店中放置了一个应用程序 而我的朋友 在两台设备上运行 4 0 3 在尝试安装我的应用程序时收到以下消息 您的设备与此版本不兼容 一台设备允许安装 而另一台设备则不允许 我允许 API 3 15 并且两台设备都是 4 0 3
  • 向量子集性能:名称与索引

    如果我有一个向量v姓名 John Murray Lisa Mike Joe Ann 0 0832090 0 0475580 0 2797860 0 1086225 0 0104590 0 0028250 时间复杂度是多少v Joe vers
  • 如何将PHP编译成操作码并在生产环境中运行?

    注意 这不是facebook最近的hiphop项目 我只是想把它转换成opcode not c c 现在还有解决办法吗 演示永远是最好的 您正在寻找的是PHP加速器 http en wikipedia org wiki PHP accele
  • 创建 Dockerfile - docker 在每个新构建上从头开始

    我正在尝试构建一个 dockerfile 迭代地添加行和测试 我的理解是 docker 将缓存已经构建的行 并从我添加的新行开始 情况似乎是 每次我在容器上调用 build 时 它只是从头开始构建 这是正常的吗 如果不是 我做错了什么 正如
  • REngine”不包含“SetDllDirectory”、“RDotNet”的定义

    My Code using System using System Collections Generic using System ComponentModel using System Data using System Drawing