RProvider
RProvider copied to clipboard
Add support for option types in RProvider
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.FSharpList
1[[Microsoft.FSharp.Core.FSharpOption
1[[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 [email protected](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(List
1 tempSymbols, Object arg) in C:\Tomas\Public\bmc\FSharp.RProvider\src\RProvider\RInterop.fs:line 450 at [email protected](IEnumerable1& next) in C:\Tomas\Public\bmc\FSharp.RProvider\src\RProvider\RInterop.fs:line 470 at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase
1.MoveNextImpl() at System.Collections.Generic.List1..ctor(IEnumerable
1 collection) at Microsoft.FSharp.Collections.SeqModule.ToArray[T](IEnumerable1 source) at RProvider.RInterop.callFunc(String packageName, String funcName, IEnumerable
1 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.
This would be a nice feature to have - I'm marking this as up-for-grabs, in case someone wants to send a PR!