fslaborg / RProvider

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

Can't use RProvider in fsdocs --eval mode #268

Open AndrewIOM opened 2 months ago

AndrewIOM commented 2 months ago

Describe the bug When trying to use RPRrovider from a .fsx file in an fsdocs docs project,

To Reproduce Steps to reproduce the behavior:

  1. Start a new fsdocs project.
  2. Add a script with the below content.
  3. Run script in dotnet fsi, then run in dotnet fsdocs watch.
(**
---
title: RProvider test
category: RProvider test
categoryindex: 1
index: 1
---
*)

#r "nuget:RProvider"

open RProvider
open RProvider.Operators
open RDotNet

try
    // R.pi |> ignore
    R.``+``([ 1.; 2. ]) |> ignore
    // R.abs(1.) |> ignore
    // printfn "%A" <| RProvider.datasets.R.volcano.GetValue<string>()
with
    | (e:exn) -> 
        printfn "Exception thrown: %s" e.Message
        printfn "Trace was: %s" e.StackTrace
(*** include-fsi-merged-output ***)

Expected behavior The script should return the same html string in both dotnet fsi and dotnet fsdocs watch.

Environment (please complete the following information):

Additional context The exception thrown is as follows:

System.ComponentModel.Composition APIs are not supported on this platform.
seq []
   at System.ComponentModel.Composition.Primitives.ComposablePartCatalog..ctor()
   at System.ComponentModel.Composition.Hosting.DirectoryCatalog..ctor(String path, String searchPattern)
   at RProvider.RInteropInternal.catalogs@114.GenerateNext(IEnumerable`1& next)
   at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl() in D:\a\_work\1\s\src\FSharp.Core\seqcore.fs:line 488
   at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source)
   at RProvider.RInteropInternal.mefContainer@99.Invoke(Unit unitVar)
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
--- End of stack trace from previous location ---
   at System.Lazy`1.CreateValue()
   at RProvider.RInteropInternal.tryGetConverter@158-1.Invoke(Type vt)
   at Microsoft.FSharp.Collections.SeqModule.TryPick[T,TResult](FSharpFunc`2 chooser, IEnumerable`1 source) in D:\a\_work\1\s\src\FSharp.Core\seq.fs:line 804
   at RProvider.RInteropInternal.convertToR[inType](REngine engine, inType value)
   at RProvider.RInteropInternal.REngine.SetValue(REngine this, Object value, FSharpOption`1 symbolName)
   at RProvider.RInteropInternal.toR(Object value)
   at RProvider.RInterop.passArg@604(List`1 tempSymbols, Object arg)
   at RProvider.RInterop.argList@630-1.GenerateNext(IEnumerable`1& next)
   at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl() in D:\a\_work\1\s\src\FSharp.Core\seqcore.fs:line 488
   at Microsoft.FSharp.Collections.SeqModule.ToArray[T](IEnumerable`1 source) in D:\a\_work\1\s\src\FSharp.Core\seq.fs:line 1027
   at RProvider.RInterop.callFunc(String packageName, String funcName, IEnumerable`1 argsByName, Object[] varArgs)
   at <StartupCode$FSI_0025>.$FSI_0025.main@()

It works with R.pi or R.abs(1.), but not more complex interactions. It seems to be related to the GetValue member on SymbolicExpression.

Querying the loaded assemblies with reflection, it seems to think that System.ComponentModel.Composition, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 is the loaded assembly version.