fslaborg / RProvider

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

Running an fsx script from "Reading and writing RData files" with fsi throws a `System.Reflection.TargetInvocationException` exception. #262

Open EverybodyKurts opened 1 year ago

EverybodyKurts commented 1 year ago

Describe the bug

Running an fsx script from Reading and writing RData files with fsi throws a System.Reflection.TargetInvocationException exception.

To Reproduce

Create a script that loads sample.rdata as shown in the Reading and writing RData files example:

open RProvider

type Sample = RData<"data/sample.rdata">
let sample = Sample()

// Easily access saved values
sample.volcano
sample.volcanoList
sample.volcanoMean

Run it in VSCode (with Ionide installed) via the Command Pallette via send file OR run it on the command line with the following command:

% dotnet fsi script.fsx
chmod: '/Users/mueller.128/.nuget/packages/rprovider/2.1.0/lib/net5.0/server/osx-arm64/RProvider.Server': No such file or directory
Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection
In addition: Warning message:
In readChar(con, 5L, useBytes = TRUE) :
  cannot open compressed file '/Users/mueller.128/.packagemanagement/nuget/Cache/sample.rdata', probable reason 'No such file or directory'

/Users/mueller.128/Developer/comrit/imrp-frontend/script.fsx(5,15): error FS3033: The type provider 'RProvider.RDataProvider' reported an error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.Exception: Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection

   at RProvider.Server.EventLoop.runServerCommandSafe[a](FSharpFunc`2 f) in /Users/runner/work/RProvider/RProvider/src/RProvider.Server/RInteropServer.fs:line 78
   at RProvider.Server.RInteropServer.RProvider.Internal.IRInteropServer.GetRDataSymbols(String file) in /Users/runner/work/RProvider/RProvider/src/RProvider.Server/RInteropServer.fs:line 107
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
   --- End of inner exception stack trace ---
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at PipeMethodCalls.RequestHandler`1.GetTypedResponseForRequest(SerializedPipeRequest request)

Expected behavior

The script to run successfully without throwing an error.

Screenshots

Screen Shot 2023-01-07 at 4 47 35 PM

Environment (please complete the following information):

Additional context Add any other context about the problem here.

EverybodyKurts commented 1 year ago

I should note I have net7.0 installed on my machine. I noticed https://github.com/fslaborg/RProvider/blob/008c08476d04eda984be5564e367f93954062f38/src/RProvider.Server/RProvider.Server.fsproj#L5 doesn't mention net7.0

EverybodyKurts commented 1 year ago

It's also worth noting that when I run a dotnet 6 bullseye container with aarch64 hardware, rprovider tries to look in a nonexistent directory:

$ dotnet fsi script.fsx
/usr/share/dotnet/sdk/6.0.404/Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3270: There was a mismatch between the processor architecture of the project being built "" and the processor architecture of the reference "/home/vscode/.nuget/packages/rprovider/2.1.0/lib/net5.0/RProvider.Server.dll", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project. [/home/vscode/.packagemanagement/nuget/Projects/845--3c980b4e-05c9-47d3-b65d-a630fd882448/Project.fsproj]
chmod: cannot access "'/home/vscode/.nuget/packages/rprovider/2.1.0/lib/net5.0/server/linux-x64/RProvider.Server'": No such file or directory
qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory

/home/vscode/.packagemanagement/nuget/Cache/fb9242c43856bc61aaeecc6eaf2047d16c0039d25de22f3eb2769b4aed1eb227.fsx(19,1): error FS3053: The type provider 'RProvider.RProvider' reported an error: The type provider constructor has thrown an exception: Failed to start the R.NET server within 20 seconds.To enable logging set RPROVIDER_LOG to an existing file name.
nhirschey commented 1 year ago

Looks like a possible resolution folder issue, such as needing to provide a resolution folder to CsvProvider so that it doesn't look for the file in the .nuget path. This arose with the introduction of #r nuget... and it looks like solving this would require adding a ResolutionFolder static type to the RData type provider.

See documentation of CsvProvider using ResolutionFolder.

Static parameters in RProvider: https://github.com/fslaborg/RProvider/blob/008c08476d04eda984be5564e367f93954062f38/src/RProvider.DesignTime/RData.fs#L98-L101

Similar in CsvProvider defining the resolution folder can be seen here