Hello,
I am trying to run a test program on my Windows 10 Enterprise (x64) machine.
I copied the following example into a new Console project (Visual Studio 2015):
using System;
using System.Linq;
using RDotNet;
namespace TestRDotNet {
class Program {
static void Main() {
// REngine.SetEnvironmentVariables();
// There are several options to initialize the engine, but by default the following suffice:
var engine = REngine.GetInstance();
// .NET Framework array to R vector.
var group1 = engine.CreateNumericVector(new double[] { 30.02, 29.99, 30.11, 29.97, 30.01, 29.99 });
engine.SetSymbol("group1", group1);
// Direct parsing from R script.
var group2 = engine.Evaluate("group2 <- c(29.89, 29.93, 29.72, 29.98, 30.02, 29.98)").AsNumeric();
// Test difference of mean and get the P-value.
var testResult = engine.Evaluate("t.test(group1, group2)").AsList();
var p = testResult["p.value"].AsNumeric().First();
Console.WriteLine("Group1: [{0}]", string.Join(", ", group1));
Console.WriteLine("Group2: [{0}]", string.Join(", ", group2));
Console.WriteLine("P-value = {0:0.000}", p);
// you should always dispose of the REngine properly.
// After disposing of the engine, you cannot reinitialize nor reuse it
engine.Dispose();
}
}
}
I also installed the following package:
PM> Install-Package R.NET.Community
Attempting to gather dependencies information for package 'R.NET.Community.1.6.5' with respect to project 'TestRDotNet', targeting '.NETFramework,Version=v4.5.1'
Attempting to resolve dependencies for package 'R.NET.Community.1.6.5' with DependencyBehavior 'Lowest'
Resolving actions to install package 'R.NET.Community.1.6.5'
Resolved actions to install package 'R.NET.Community.1.6.5'
Adding package 'R.NET.Community.1.6.5' to folder 'C:\sm\Misc\TestRDotNet\packages'
Added package 'R.NET.Community.1.6.5' to folder 'C:\sm\Misc\TestRDotNet\packages'
Added package 'R.NET.Community.1.6.5' to 'packages.config'
Successfully installed 'R.NET.Community 1.6.5' to TestRDotNet
The test program compiled without any errors or warning messages.
When I tried to run the program, I got the following run-time error on the first line:
var engine = REngine.GetInstance();
The error message was:
System.ApplicationException was unhandled
HResult=-2146232832
Message=Windows Registry key 'SOFTWARE\R-core' not found in HKEY_LOCAL_MACHINE nor HKEY_CURRENT_USER
Source=RDotNet.NativeLibrary
StackTrace:
at RDotNet.NativeLibrary.NativeUtility.GetRCoreRegistryKeyWin32(StringBuilder logger)
at RDotNet.NativeLibrary.NativeUtility.FindRHome(String rPath, StringBuilder logger)
at RDotNet.NativeLibrary.NativeUtility.FindRPaths(String& rPath, String& rHome, StringBuilder logSetEnvVar)
at RDotNet.NativeLibrary.NativeUtility.SetEnvironmentVariables(String rPath, String rHome)
at RDotNet.REngine.SetEnvironmentVariables(String rPath, String rHome)
at RDotNet.REngine.GetInstance(String dll, Boolean initialize, StartupParameter parameter, ICharacterDevice device)
at TestRDotNet.Program.Main() in C:\sm\Misc\TestRDotNet\TestRDotNet\Program.cs:line 10
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Any help will be greatly appreciated.
Charles