Fatal error: unable to open base package

Aug 22, 2011 at 7:56 PM

Hello,

I've heard great things about R.NET libraries, and wanted to try them out. But, I'm running into a problem connecting to R...

Setup:

I'm using Visual Studios Express 2010 C# .NET 4.0 (32-bit), the R.NET Windows binary (x86), and R 2.13.1. My platform is Windows 7 (64-bit). 

Code:   

REngine.SetDllDirectory(@"C:\Program Files\R\R-2.13.1\bin\i386");           

 

using (REngine engine = REngine.CreateInstance("RDotNet", new[] { "-q" }))
{
	// .NET Framework array to R vector.
	NumericVector group1 = engine.CreateNumericVector(new double[] { 30.02, 29.99, 30.11, 29.97, 30.01, 29.99 });
	engine.SetSymbol("group1", group1);
}

 

When I run this code I receive the following error:

Fatal error: unable to open the base package
The program '[4092] Testing_RdotNet.vshost.exe: Managed (v4.0.30319)' has exited with code 2 (0x2).

I have tried uninstalling R and then R installing it, and still get the same error. R runs beautifully on my computer when I run it by itself or with RStudio, so it's loading the base package by itself. 

Also, I have asked others in my workspace to just give the program a try and it runs just fine for them, so there's something different about my R setup.

I was wondering if anyone else has ever seen this error message before, or may have some ideas that I could try? Any help is greatly appreciated! 

Best,
Joe 

Aug 22, 2011 at 9:24 PM

Very possibly a dumb idea but I'll throw it out there.  I am running 64-bit Vista at home, and when I installed R there I needed to point R.NET to C:\Program Files (x86)\R\... to get things up and running.  I do not have access to a Windows 7 64-bit installation at the moment so I can't remember if that two-location Program Files thing made it from Vista to 7, but if so, I'd suggest giving that a shot.

Aug 22, 2011 at 11:24 PM

Thanks for the suggestion ascruggs. I was thinking about that too because the two-location Program Files were carried over from Vista to 7. However, R 2.13.1 only installs in the "Program Files" directory, and under "bin" it splits between "i386" (32-bit) and "x64" (64-bit). 

But, I think i figured out what the problem is. Although I set the REngine dll directory to i386 (REngine.SetDllDirectory(@"C:\Program Files\R\R-2.13.1\bin\i386");), my system path was set to C:\Program Files\R\R-2.13.1\bin\x64.

I thought I was manually setting R.NET, but it appears that something about it still uses the system path. As soon as I changed my path it worked, go figure.

Hopefully, this will help someone else out too.

Mar 22, 2012 at 4:14 AM
Edited Mar 22, 2012 at 4:15 AM

I am having the exact same problem (Fatal error: unable to open base package). I am running on Windows 7 (64-bit) and using Visual Studio 2010 and R-2.14.1. I've tried compiling both i386 and x64 code, referencing  the appropriate R.NET dll, but still can't get past this error.

I'm sure it is something to to with the SetDllDirectory call but I can't seem to get the right combination. Although SetDllDirectory returns True it doesn't appear to be locating R.dll. The split between i386 and x64 could be the issue. I assume if I'm compiling in 64-bit then I should point to the 64-bit R.dll and reference the 64-bit R.NET binary and have my system path pointing to the same place. Is there some way I can check all these locations are set correctly?

Any help would be much appreciated.

 

Apr 26, 2012 at 1:48 PM

I'm having a similar problem with 2.15.0, but I'm in a bit of an obscure OS - XP x64. I changed the .SetDLLDirectory(@"...\i386") to x64 and was throw the error: "DLL was not found." It seems like it finds the .dll in the i386 folder, as it should, but something is not building correctly. Any chance the latest R.NET.dll was complied with a different version of R and that is the cause of this?

Apr 26, 2012 at 2:06 PM

I've tried the same with 2.12.0 and have confirmed this behavior is in both versions of R. Seems to be something else.

Developer
Apr 28, 2012 at 2:48 AM

You may want to specify the R_HOME path when starting R. I needed to at some point, though with my latest setup even if I try to specify an incorrect location for R_HOME R falls back on its feet and finds the 'library' folder, where you'd expect the 'base' package. I thus cannot reproduce the issue, try as I may, but I think R fails to infer the R_HOME env variable from the dll path. You may investigate further your program with Console.WriteLine(System.Environment.GetEnvironmentVariable("R_HOME")) to figure out what is going on.

Also the documentation of R_home in R, and the R Administration manual may shed some light.

 

// main(string[] args):
var rdllloc = args.Length > 0 ? args[0] : @"c:\bin\R\R\bin\x64";
REngine.SetDllDirectory(rdllloc);
using (REngine engine = REngine.CreateInstance("RDotNet", new[] { @"R_HOME=c:\bin\R\R" }))
{
// body
}

May 27, 2013 at 10:16 PM
Edited May 27, 2013 at 10:17 PM
after searching and testing, I was able to resolve this error. You have to set the variable R_HOME, at the root of R, since apparently looking at some of the folders in the root directory of the program. In c # it would be something like: Environment.SetEnvironmentVariable ("R_HOME", "C: \ \ Program Files \ \ R \ \ R-2.15.2 \ \");

Hope this helps

<a href="http://www.redantares.com">Desarrollo de software en mexico</a>
Jun 17, 2013 at 12:20 PM
Thanks fcosaid . I was using R-2.15.1 and your suggestion worked very well for me , on Windows 7 Professional . Incidentally I did not do an R Install , but just copied the R folders from my previous Windows XP install . But rather than create R_HOME etc,. I just set the environment variable in code as you suggested.