gpt4 book ai didi

c# - REngine' 不包含 'SetDllDirectory' 的定义,'RDotNet

转载 作者:太空狗 更新时间:2023-10-30 01:15:23 29 4
gpt4 key购买 nike

我的代码

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();
}
}
}
}

低于错误

错误 1“RDotNet.REngine”不包含“SetDllDirectory”的定义 C:\Users\Shrinith_Sanil\Documents\Visual Studio 2013\Projects\Con_R\Con_R\Program.cs 161 21 Con_R

错误 2“RDotNet.REngine”不包含“CreateInstance”的定义 C:\Users\Shrinith_Sanil\Documents\Visual Studio 2013\Projects\Con_R\Con_R\Program.cs 164 45 Con_R

已添加

错误 3“RDotNet.REngine”不包含“EagerEvaluate”的定义,并且找不到接受“RDotNet.REngine”类型的第一个参数的扩展方法“EagerEvaluate”(您是否缺少 using 指令或程序集引用?)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);
}


}
}

关于c# - REngine' 不包含 'SetDllDirectory' 的定义,'RDotNet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38525902/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com