Quantcast
Channel: R.NET
Viewing all articles
Browse latest Browse all 1634

Edited Issue: Frequently calling R causes failure of RDotNet.ParseException or System.AccessViolationException [67]

$
0
0
I test RDotNet in F# by using RProvider.

This is my F# code, which frequently fails for RDotNet.ParseException or sometimes System.AccessViolationException.

My environment is
Windows 8.1 Ultimate x64
Microsoft.NET Framework 4.5.1
F# 3.1
R 3.0.2 x64

The same problem also occurs in .NET 4.5, F# 3.0, and R 3.0.x x86

``` F#
module RFSharpTest.Program

open System
open RDotNet
open RProvider
open RProvider.``base``
open RProvider.stats
open RProvider.utils

[<EntryPoint>]
let main argv =
[1..1000]
|> List.iter (fun i ->
let dic = dict [("ma",R.c(0.6,0.4,0.1).Value)]
let list = R.list(dic)
let data1 = R.arima_sim(model=list,n=50)
let model = R.arima(x=data1,order=R.c(0,0,5))
printfn "test"
)
Console.Read()
0 // return an integer exit code
```

It's not rare since I tested for other more formal purposes. For example, I iterated a long list of data rows for each an unitrootTest (in R package fUnitRoots) is called to provide some test statistic. This is almost the same situation as the code presented above: both involve intensive iteration of calling RDotNet library or calling R. Very frequently, the program fails.

However, temporarily I find a way to avoid this: in the end of each iteration, I force GC to collect all generations (or just generation 0), and the problem does not appear again. As long as I remove this line of code, the same problem occurs.

Here's my new "safe" code:
``` F#
module RFSharpTest.Program

open System
open RDotNet
open RProvider
open RProvider.``base``
open RProvider.stats
open RProvider.utils

[<EntryPoint>]
let main argv =
[1..1000]
|> List.iter (fun i ->
let dic = dict [("ma",R.c(0.6,0.4,0.1).Value)]
let list = R.list(dic)
let data1 = R.arima_sim(model=list,n=50)
let model = R.arima(x=data1,order=R.c(0,0,5))
printfn "test"
GC.Collect()
)
Console.Read()
```

Now, I see it's unsafe to intensively call RDotNet (at least through RProvider) unless I add code to force GC collection frequently.

Is there a way to solve this problem with more reasons?

Viewing all articles
Browse latest Browse all 1634

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>