fslaborg / RProvider

Access R packages from F#
http://fslab.org/RProvider/
Other
235 stars 69 forks source link

Updating the dependency to R.NET 1.6.3 #152

Closed jmp75 closed 9 years ago

jmp75 commented 9 years ago

I have moved R.NET to use packet, and re-released 1.6.3. There are a couple of fixes to text parsing (https://rdotnet.codeplex.com/workitem/165) and more recently (https://github.com/jmp75/rdotnet/issues/14). These issues may not be encountered often from F# given the RDP design, but this is better fixed.

tpetricek commented 9 years ago

Thank you!

I was just thinking we should release a new version of R provider soon. I'll have a look at the changes in the next 2 days and report back.

tpetricek commented 9 years ago

The changes look good to me!

@hmansell Are you OK with me releasing a new version? This updates the R.NET dependency to the latest version (which contains a few fixes - I even submitted one of them myself to improve the R provider experience on Mac/Linux).

hmansell commented 9 years ago

@tpetricek absolutely! Pls create s new version.

tpetricek commented 9 years ago

Released, thank you!

I also need to propagate the update to Deedle and FsLab, which I'll try to do ASAP too.

tpetricek commented 9 years ago

I just tried to update the version of R provider used internally at BMC and I keep getting errors there, quite likely because (at least on my machine) I have an older version of R (v2.14.1). I just installed this version on my laptop and I get the same issue, which is that the following initialization call in R provider:

let engine = REngine.GetInstance(null, true, null, characterDevice)

Fails with the following error:

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at System.Runtime.InteropServices.Marshal.ReadInt32(IntPtr ptr, Int32 ofs) at RDotNet.REngine.GetVisible()\r\n at RDotNet.REngine.Parse(String statement, StringBuilder incompleteStatement)\r\n at RDotNet.REngine.d__0.MoveNext() at System.Linq.Enumerable.LastOrDefault[TSource](IEnumerable`1 source) at RDotNet.REngine.Evaluate(String statement) at RDotNet.REngine.Initialize(StartupParameter parameter, ICharacterDevice device, Boolean setupMainLoop) at RDotNet.REngine.GetInstance(String dll, Boolean initialize, StartupParameter parameter, ICharacterDevice device) at RProvider.Internal.RInit.engine@114.Invoke() in RInit.fs:line 118

I guess updating to more recent R would solve the issue, but I'm afraid we cannot easily do that (cc @hmansell).

@jmp75 Do you have any idea what might be going wrong here? (Or suggestions how to debug the issue).

tpetricek commented 9 years ago

I figured it out!

At the end of the Initialize method R.NET has the following call:

Evaluate(string.Format("invisible(memory.limit({0}))", (this.parameter.MaxMemorySize / 1048576UL)));

Using 32bit version of R 2.14.1, this fails on my machine (here is output from normal command line):

> invisible(memory.limit(17592186044415))
Error in memory.size(size) :
  don't be silly!: your machine has a 4Gb address limit

I guess old version of R reports that my machine has lots of RAM even when running in 32 bit mode where I cannot actually use it (or something like that). I'll send a PR to R.NET that wraps this in exception handler (for compatibility with old versions of R).

tpetricek commented 9 years ago

Oh, actually, it was something else in the end. In the GetVisible method, we have the following:

var symbol = DangerousGetHandle("R_Visible");
var value = Marshal.ReadInt32(symbol);
var result = Convert.ToBoolean(value);
return result;

It turns out that with my version of R, the first call returns 0 and we get a nice access violation exception reading from the address 0 :-). PR with a fix coming soon!