fslaborg / RProvider

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

Add support for option types in RProvider #179

Open s952163 opened 7 years ago

s952163 commented 7 years ago

Currently lists that contain the Option type cannot be directly passed to RProvider but have to be converted.

The following generates an error:

let ints = [Some 2; None; Some 4; Some 5; None]
let floats = [Some 2.; None; Some 4.; Some 5.; None]
let strings = [Some "a"; None; Some "c"; Some "d"; None]

strings |> R.data_frame
floats  |> R.plot 

System.Exception: No converter registered for type Microsoft.FSharp.Collections.FSharpList1[[Microsoft.FSharp.Core.FSharpOption1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]] or any of its base types at RProvider.RInteropInternal.convertToR@164.Invoke(String message) in C:\Tomas\Public\bmc\FSharp.RProvider\src\RProvider\RInterop.fs:line 164 at RProvider.RInteropInternal.REngine.SetValue(REngine this, Object value, FSharpOption1 symbolName) in C:\Tomas\Public\bmc\FSharp.RProvider\src\RProvider\RInterop.fs:line 274 at RProvider.RInteropInternal.toR(Object value) in C:\Tomas\Public\bmc\FSharp.RProvider\src\RProvider\RInterop.fs:line 287 at RProvider.RInterop.passArg@447(List1 tempSymbols, Object arg) in C:\Tomas\Public\bmc\FSharp.RProvider\src\RProvider\RInterop.fs:line 450 at RProvider.RInterop.argList@468-1.GenerateNext(IEnumerable1& next) in C:\Tomas\Public\bmc\FSharp.RProvider\src\RProvider\RInterop.fs:line 470 at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase1.MoveNextImpl() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at Microsoft.FSharp.Collections.SeqModule.ToArray[T](IEnumerable1 source) at RProvider.RInterop.callFunc(String packageName, String funcName, IEnumerable1 argsByName, Object[] varArgs) in C:\Tomas\Public\bmc\FSharp.RProvider\src\RProvider\RInterop.fs:line 466 at <StartupCode$FSI_0064>.$FSI_0064.main@() in C:\Users\verepet\documents\visual studio 2015\Projects\StackOverflow6\StackOverflow6\Script5.fsx:line 90 Stopped due to error

Workaround is to convert the lists:


let floats' = [2.; nan; 4.; 5.; nan]
let strings' = ["a"; "NA"; "c"; "d"; "NA"]

strings' |> R.data_frame
floats' |> R.plot
val it : SymbolicExpression =   ...
1   a
2  NA
3   c
4   d
5  NA

Ideally the type provider should take care of this conversion.

tpetricek commented 7 years ago

This would be a nice feature to have - I'm marking this as up-for-grabs, in case someone wants to send a PR!