1
votes

I'm parsing a CSV with F#'s CsvProvider and successfully creating two lists :

let times = [ for row in airinfo.Rows -> row.Time ]

let passengers = [ for row in airinfo.Rows -> row.AirPassengers ]

times is a decimal list and passengers is an int list.

Ultimately I'm trying to run: R.plot (times, passengers)

For starters though R.plot passengers works, but R.plot times doesn't, which leads me to believe that the problem is in plotting a decimal list.

I get the following exception:

System.Exception: No converter registered for type Microsoft.FSharp.Collections.FSharpList`1[[System.Decimal, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] or any of its base types

  at [email protected] (System.String message) [0x00001] in <57161c90b86b2a10a7450383901c1657>:0   at Microsoft.FSharp.Core.PrintfImpl+StringPrintfEnv1[TResult].Finalize () [0x00012] in <5893d081904cf4daa745038381d09358>:0   at Microsoft.FSharp.Core.PrintfImpl+Final1@224[TState,TResidue,TResult,A].Invoke (Microsoft.FSharp.Core.FSharpFunc2[T,TResult] env, A a) [0x00038] in <5893d081904cf4daa745038381d09358>:0   at Microsoft.FSharp.Core.OptimizedClosures+Invoke@3253[T2,TResult,T1].Invoke (T2 u) [0x00001] in <5893d081904cf4daa745038381d09358>:0   at RProvider.RInteropInternal.convertToR[inType] (RDotNet.REngine engine, inType value) [0x00061] in <57161c90b86b2a10a7450383901c1657>:0   at RProvider.RInteropInternal.REngine.SetValue (RDotNet.REngine this, System.Object value, Microsoft.FSharp.Core.FSharpOption1[T] symbolName) [0x00001] in <57161c90b86b2a10a7450383901c1657>:0   at RProvider.RInteropInternal.toR (System.Object value) [0x00019] in <57161c90b86b2a10a7450383901c1657>:0   at RProvider.RInterop.passArg@447 (System.Collections.Generic.List1[T] tempSymbols, System.Object arg) [0x00123] in <57161c90b86b2a10a7450383901c1657>:0   at [email protected] (System.Collections.Generic.IEnumerable1[System.String]& next) [0x000d8] in <57161c90b86b2a10a7450383901c1657>:0   at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase1[T].MoveNextImpl () [0x00017] in <5893d081904cf4daa745038381d09358>:0   at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase1[T].System-Collections-IEnumerator-MoveNext () [0x00001] in <5893d081904cf4daa745038381d09358>:0   at System.Collections.Generic.List1[T]..ctor (System.Collections.Generic.IEnumerable1[T] collection) [0x00077] in <48b95f3df5804531818f80e28ec60191>:0   at Microsoft.FSharp.Collections.SeqModule.ToArray[T] (System.Collections.Generic.IEnumerable1[T] source) [0x0006a] in <5893d081904cf4daa745038381d09358>:0   at RProvider.RInterop.callFunc (System.String packageName, System.String funcName, System.Collections.Generic.IEnumerable`1[T] argsByName, System.Object[] varArgs) [0x0001d] in <57161c90b86b2a10a7450383901c1657>:0   at .$FSI_0012.main@ () [0x0002f] in <511174b5879343f6b1c4aa72a97ef951>:0   at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)   at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <48b95f3df5804531818f80e28ec60191>:0

Any help is greatly appreciated.

1
re-format the exception text as block quote - Imran Ali
The R provider is fairly low level, and it doesn't know about some F# (like option) and .NET types. Just convert your decimal into float or some other number format that can be digested by it. You also need to probably box it. Can you add the full code you are calling? This as an example cannot be reproduced. - s952163

1 Answers

0
votes

You will need to convert the decimal list into a number type the RProvider knows about. Here's an example that works for me:

#load @"..\packages\RProvider\RProvider.fsx"

open System
open RDotNet
open RProvider
open RProvider.graphics

let floatList = [1. ..10.]
let decList = [1M .. 10M ]

R.plot(floatList) // this works
R.plot(decList) // Syystem.exception

System.Exception: No converter registered for type Microsoft.FSharp.Collections.FSharpList`1[[System.Decimal, mscorlib, Version=4.0.0.0, Cul ture=neutral, PublicKeyToken=b77a5c561934e089]] or any of its base types

But you can convert your list into another type:

decList 
|> List.map float 
|> R.plot

enter image description here

Also, if you want to use one list as a label maybe you should convert into string, not float as I did above.