Git Product home page Git Product logo

Comments (3)

hmansell avatar hmansell commented on June 27, 2024

It's likely some kind of subtle bug in R.NET. We don't do any unmanaged memory management in RProvider. Presumably you are using it in some way that looks the same but actually is subtly different. I fixed some bugs in SymbolicExpression resource management before, but I am sure some remain. It's very difficult to do the interop with unmanaged code correctly.

When I get a chance, I'll try to take a look. Having a robust repro helps!

from rprovider.

renkun-ken avatar renkun-ken commented on June 27, 2024

I raised an issue in RDotNet project (https://rdotnet.codeplex.com/workitem/67) and they redirect me to Issue #4. Here I provide a minimal reproducible example where RProvider causes an error while RDotNet does not.

Using RDotNet:

open RDotNet
open RDotNet.NativeLibrary
open RDotNet.Internals

let REngine = REngine.CreateInstance("R_INSTANCE", @"C:\Program Files\R\R-3.0.2\bin\x64\R.dll")
let R (statement:string) = REngine.Evaluate statement
REngine.Initialize()

[<EntryPoint>]
let main argv = 
    let beta = 
        [ for i in 1..1000 do
              let x = R "x <- rnorm(1000)"
              let y = R "y <- rnorm(1000)"
              let m = R "m <- lm(y~x)"
              let beta = (R "m$coefficients[2]").AsNumeric().[0]
              printfn "%f" beta
              yield beta ]

    let meanBeta = beta |> List.average
    0 // return an integer exit code

This code runs without any error.

RProvider:

open RDotNet
open RProvider
open RProvider.``base``
open RProvider.stats

[<EntryPoint>]
let main argv =
    let beta =
        [
            for i in 1..1000 do
                let x = R.rnorm(1000)
                let y = R.rnorm(1000)
                let df = R.data_frame(namedParams [ "y", box y; "x", box x; ])
                let m = R.lm(df)
                let beta = m.AsList().["coefficients"].AsNumeric().[1]
                printfn "%f" beta
                yield beta
        ]
    let meanBeta = beta |> List.average
    0

Every time I run the code above, at some i an error occurs at let df = R.data_frame or let m = R.lm(df):

An unhandled exception of type 'System.AccessViolationException' occurred in RDotNet.dll
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

How do we debug the code and see what happens?

from rprovider.

tpetricek avatar tpetricek commented on June 27, 2024

This will be fixed once we update to new version of R.NET & merge @dcharbon changes, so I'm closing this.

from rprovider.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.