fslaborg / RProvider

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

FSI printing for R SymbolicExpressions missing since change to #r nuget #241

Closed AndrewIOM closed 2 years ago

AndrewIOM commented 2 years ago

Describe the bug In the old RProvider, the user used to call in RProvider to an F# script using a file "rprovider.fsx" in the nuget package. This had the line to register the R type printer:

do fsi.AddPrinter(fun (synexpr:RDotNet.SymbolicExpression) -> synexpr.Print())

Using the new #r "nuget:RProvider" package management feature, we do not call this line so the user is met with hard-to-read output in the console.

To Reproduce Steps to reproduce the behavior:

  1. In dotnet fsi run:
    #r "nuget:RProvider,2.0.1-beta2"
    open RProvider
    R.c(1.,2.,3.,)
  2. See console output:
    
    Microsoft (R) F# Interactive version 12.0.0.0 for F# 6.0
    Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

r "nuget:RProvider,2.0.1-beta2"

  • ;; open RProvider [Loading /var/folders/j1/x5nz9rcj5j50tb49xp3sy33w0000gn/T/nuget/6370--f59a32ee-dff5-4aa2-8c60-ceeccc9fb433/Project.fsproj.fsx] Binding session to '/Users/andrewmartin/.nuget/packages/pipemethodcalls/3.0.4/lib/netstandard2.0/PipeMethodCalls.dll'... Binding session to '/Users/andrewmartin/.nuget/packages/newtonsoft.json/13.0.1/lib/netstandard2.0/Newtonsoft.Json.dll'... namespace FSI_0002.Project

open RProvider

  • ;; R.c(1.,2.,3.);; Binding session to '/Users/andrewmartin/.nuget/packages/r.net/1.9.0/lib/netstandard2.0/RDotNet.dll'... Binding session to '/Users/andrewmartin/.nuget/packages/system.componentmodel.composition/5.0.0/lib/netcoreapp2.0/System.ComponentModel.Composition.dll'... Binding session to '/Users/andrewmartin/.nuget/packages/dynamicinterop/0.9.1/lib/netstandard2.0/DynamicInterop.dll'... Binding session to '/Users/andrewmartin/.nuget/packages/r.net.fsharp/1.9.0/lib/netstandard2.0/RDotNet.FSharp.dll'... val it: RDotNet.SymbolicExpression = RDotNet.SymbolicExpression {Engine = RDotNet.REngine; IsClosed = false; IsInvalid = false; IsProtected = true; Type = NumericVector;}

Expected behavior The output should be displayed as below:

> do fsi.AddPrinter(fun (synexpr:RDotNet.SymbolicExpression) -> synexpr.Print())
- ;;
val it: unit = ()

> R.c(1.,2.,3);;
val it: RDotNet.SymbolicExpression = [1] 1 2 3

Screenshots NA

Environment (please complete the following information):

Additional context Add any other context about the problem here.

AndrewIOM commented 2 years ago

Implemented a solution that isn't ideal but is the best approach right now. There is now a FSIPrinters module that contains print functions you can call in an fsi script using fsi.AddPrinter

halcwb commented 2 years ago

@AndrewIOM. This isn't yet in the latest release (2.0.2)?

nhirschey commented 2 years ago

@halcwb no but you can also add the below line to the top of your script and it will work.

fsi.AddPrinter(fun (synexpr:RDotNet.SymbolicExpression) -> synexpr.Print())
halcwb commented 2 years ago

Thanks, that's what I did.

AndrewIOM commented 2 years ago

Hi @halcwb, I missed putting a release out with this feature. I've now released 2.0.3 with the FSI printer module included.