fslaborg / RProvider

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

Calling function fails with RProvider but works with RDotNet #177

Closed torbonde closed 2 years ago

torbonde commented 8 years ago

When calling the function qspd from the spd library I get the following error

Error in UseMethod("qspd") : 
  no applicable method for 'qspd' applied to an object of class "c('double', 'numeric')"
RDotNet.EvaluationException: Error in UseMethod("qspd") : 
>   no applicable method for 'qspd' applied to an object of class "c('double', 'numeric')"

   at RDotNet.REngine.Parse(String statement, StringBuilder incompleteStatement)
   at RDotNet.REngine.<Defer>d__0.MoveNext()
   at System.Linq.Enumerable.LastOrDefault[TSource](IEnumerable`1 source)
   at RDotNet.REngine.Evaluate(String statement)
   at RProvider.RInteropInternal.eval@292.Invoke(Unit unitVar0) in C:\Tomas\Public\bmc\FSharp.RProvider\src\RProvider\RInterop.fs:line 293
   at <StartupCode$FSI_0026>.$FSI_0026.main@() in C:\projects\scripts\rprovider.fsx:line 12
Stopped due to error

It works when I use RDotNet directly, which makes me think the issue is with the RProvider. The following chunk of code reproduces the issue

#load "packages/RProvider/RProvider.fsx"

open System
open RProvider.spd
open RDotNet

let rnd = Random(100)
let xs = [ for _ in 1..1000 -> rnd.NextDouble()**2. ]

// Doesn't work
let kdefit = R.spdfit(xs)
let q = R.qspd(p = 0.95, fit = kdefit)

// Works
let engine = RDotNet.REngine.GetInstance()
engine.Evaluate("library(spd)")
engine.SetSymbol("kdefit", kdefit)
let q' = engine.Evaluate("qspd(p = 0.95, fit = kdefit)")

// Also works
engine.SetSymbol("xs", engine.CreateNumericVector(xs))
engine.Evaluate("kdefit1 <- spdfit(xs)")
let q'' = engine.Evaluate("qspd(p = 0.95, fit = kdefit1)")
laygr commented 7 years ago

have you tried loading the library manually before anything else?

AndrewIOM commented 3 years ago

Cannot reproduce in latest RProvider v2 (macOS). All lines work fine and three sections all produce same answer. Looks like this issue has been fixed indirectly.

> let rnd = Random(100)
- let xs = [ for _ in 1..1000 -> rnd.NextDouble()**2. ]
- 
- // Doesn't work
- let kdefit = R.spdfit(xs)
- let q = R.qspd(p = 0.95, fit = kdefit)
- 
- // Works
- let engine = RDotNet.REngine.GetInstance()
- engine.Evaluate("library(spd)")
- engine.SetSymbol("kdefit", kdefit)
- let q' = engine.Evaluate("qspd(p = 0.95, fit = kdefit)")
- 
- // Also works
- engine.SetSymbol("xs", engine.CreateNumericVector(xs))
- engine.Evaluate("kdefit1 <- spdfit(xs)")
- let q'' = engine.Evaluate("qspd(p = 0.95, fit = kdefit1)");;
val rnd : Random
val xs : float list =
  [0.9385243978; 0.02534053873; 0.4446512291; 0.8144236733; 0.125746217;
   0.8999661605; 0.5065123705; 0.372854531; 0.1219544649; 0.02214567264;
   0.931146024; 0.2902614953; 0.1427063636; 0.2450634178; 0.9591025763;
   0.2327643903; 0.8069018708; 0.9905818537; 0.1476248424; 0.001230608741;
   0.01080804149; 0.1457113327; 0.7963834909; 0.9355012408; 0.2505135948;
   0.7133241416; 0.829037634; 0.4204436361; 0.02826266476; 0.3807741763;
   0.01100374519; 0.6304509221; 0.2596600663; 0.2456254358; 0.314227323;
   0.00936351379; 0.7487871994; 0.2818402657; 0.2193355556; 0.5442942814;
   0.07547315018; 0.2483589745; 0.1113073705; 0.3479248588; 0.3977770783;
   0.7374673966; 0.1290920203; 0.0005663577735; 0.8394150443; 0.1920646807;
   0.000784556997; 0.6221616601; 0.08736939472; 0.740734351; 0.04747158097;
   0.3446314017; 0.07117365339; 0.4894522018; 0.1615565021; 0.2601223808;
   0.001455454934; 0.004004430879; 0.1958090116; 0.5360447557; 0.001928569746;
   0.02922379385; 0.0008520974587; 0.7782041985; 0.8732509536; 0.7789343492;
   0.3808515479; 0.1349760485; 0.2776731897; 0.417906341; 0.5781416462;
   0.366757971; 0.002313027617; 0.09153750352; 0.1132439748; 0.4118483403;
   0.2355077517; 0.7862666219; 0.5361465505; 0.5327002733; 0.3469905951;
   0.09993595719; 0.2484287299; 0.4210832227; 0.07713194774; 0.9477152546;
   0.6888690302; 0.02746189328; 0.01662691188; 0.9183595869; 0.4894577903;
   0.04470822599; 0.003119574612; 0.3617743633; 0.2980461953; 0.2113664099;
   ...]
val kdefit : SymbolicExpression =

Title:

Tail Fit: GPD
Kernel Fit: normal
Tail Estimation Method:  mle 

Upper Tail:
-----------------------------------------
Estimated Parameters:
      xi     beta 
-1.03515  0.17632 
Threshold: 0.82716 
-----------------------------------------

Lower Tail:
-----------------------------------------
Estimated Parameters:
      xi     beta 
-2.36054  0.01878 
Threshold: 0.00797 
-----------------------------------------

Description

val q : SymbolicExpression = [1] 0.9139386

val engine : REngine
val q' : SymbolicExpression = [1] 0.9139386

val q'' : SymbolicExpression = [1] 0.9139386
AndrewIOM commented 2 years ago

Closing for now. If you find the issue again, please reopen.