fslaborg / Deedle

Easy to use .NET library for data and time series manipulation and for scientific programming
http://fslab.org/Deedle/
BSD 2-Clause "Simplified" License
940 stars 197 forks source link

Borrow the RinRuby samples #82

Open forki opened 10 years ago

forki commented 10 years ago

You have probably already seen https://sites.google.com/a/ddahl.org/rinruby-users/ - It would be interesting to compare the samples to deedle/FSharp.Data/RTypeProvider.

What do you think?

hmansell commented 10 years ago

Would definitely be an interesting exercise/blog post.

On Fri, Nov 29, 2013 at 11:01 AM, Steffen Forkmann <notifications@github.com

wrote:

You have probably already seen https://sites.google.com/a/ddahl.org/rinruby-users/ - It would be interesting to compare the samples to deedle/FSharp.Data/RTypeProvider.

What do you think?

— Reply to this email directly or view it on GitHubhttps://github.com/BlueMountainCapital/Deedle/issues/82 .

forki commented 10 years ago

Hi,

I am trying to copy the first sample and I'm having problems to get Deedle/fslab/R to plot a barplot.

The data can be found here.

#I "../packages/FsLab.0.0.6-beta"
#load "FsLab.fsx"

open System
open System.IO
open Deedle
open FSharp.Charting
open RProvider
open RProvider.``base``
open RProvider.graphics
open RDotNet

let words = 
    Path.Combine(__SOURCE_DIRECTORY__,"gettysburg.txt")
    |> File.ReadAllText
    |> fun text -> text.ToLower().Split()    
    |> Series.ofValues

let frame =
    ["Words" => words]
    |> Frame.ofColumns
    |> Frame.groupRowsByString "Words"
    |> Frame.countLevel fst
    |> Frame.filterRowValues (fun row -> row.GetAs<int> "Words" >= 3)
    |> Frame.filterRows (fun row _ -> row.Length >= 4)

let widgets = [ 3; 8; 12; 15; 19; 18; 18; 20; ]
R.plot(widgets)  // this works

So far so good. Deedle can plot via R on my machine.

Now I try to plot via R

R.plot(frame)  

and get

System.Exception: No converter registered for type Deedle.Frame`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] or any of its base types
   at RProvider.RInteropInternal.convertToR@102.Invoke(String message) in c:\dev\git\RProvider\src\RProvider\RInterop.fs:line 102
   at RProvider.RInteropInternal.REngine.SetValue(REngine this, Object value, FSharpOption`1 symbolName) in c:\dev\git\RProvider\src\RProvider\RInterop.fs:line 212
   at RProvider.RInteropInternal.toR(Object value) in c:\dev\git\RProvider\src\RProvider\RInterop.fs:line 225
   at RProvider.RInterop.passArg@312(List`1 tempSymbols, Object arg) in c:\dev\git\RProvider\src\RProvider\RInterop.fs:line 326
   at RProvider.RInterop.argList@333.GenerateNext(IEnumerable`1& next) in c:\dev\git\RProvider\src\RProvider\RInterop.fs:line 334
   at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl()
   at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.System-Collections-IEnumerator-MoveNext()
   at Microsoft.FSharp.Collections.SeqModule.ToArray[T](IEnumerable`1 source)
>    at RProvider.RInterop.callFunc(String packageName, String funcName, IEnumerable`1 argsByName, Object[] varArgs) in c:\dev\git\RProvider\src\RProvider\RInterop.fs:line 331
   at RProvider.RInterop.call(String packageName, String funcName, String serializedRVal, Object[] namedArgs, Object[] varArgs) in c:\dev\git\RProvider\src\RProvider\RInterop.fs:line 375
   at <StartupCode$FSI_0019>.$FSI_0019.main@()
Stopped due to error
forki commented 10 years ago

Seems to be the same problem as http://stackoverflow.com/questions/20425017/deedle-frame-to-r

forki commented 10 years ago

Using https://github.com/tpetricek/FsLab/pull/5 I succeed to plot a barchart with FSharp.Charting:

image

but I still have the problem with R.

tpetricek commented 10 years ago

It looks like installing the FsLab package does not correctly invoke the init script in Deedle.RProvider package which is supposed to copy the files (see the SO question).

Not sure why this is not working - but depending on this is probably not a good idea anyway (because it does not work with package restore).

But then, explicitly looking for plugin DLL files in ../packages/*/lib/net40 in the RProvider sounds like an ugly hack :-( (and it would not work without adding AppDomain assembly resolution hack that does the same for referenced libraries... but maybe that's what we should do... thoughts ?)

forki commented 10 years ago

Is there something I can do manually?

tpetricek commented 10 years ago

Copy Deedle.dll and Deedle.RPlugin.dll to the folder where RProvider.dll lives (they are in their corresponding subdirectories in packages).

forki commented 10 years ago

ok I can confirm that this is the problem.

image

forki commented 10 years ago

Maybe the fslab.fsx script can copy the files

forki commented 10 years ago

Quick side question? How can I sort the series?

tpetricek commented 10 years ago

The fsx script could copy the files - which would work nicely in interactive scripting scenario, but it would not work when you want to use the libraries in a project (the type provider is still loaded from the packages folder...)

As for sorting, there is only a function to sort series by keys (Series.sort, I think). I suppose we should add other options for sorting - but the problem is that we do not really guarantee that the ordering will be preserved unless the series is sorted by keys... what is the use case that you're looking at?

forki commented 10 years ago

The use case is the bar chart. It should be sorted by word count

hmansell commented 10 years ago

I think we should always preserve order. In other words, the series is always ordered but not necessarily by the natural order of its keys.

Howard

On Dec 8, 2013, at 5:37 AM, "Steffen Forkmann" notifications@github.com<mailto:notifications@github.com> wrote:

The use case is the bar chart. It should be sorted by word count

— Reply to this email directly or view it on GitHubhttps://github.com/BlueMountainCapital/Deedle/issues/82#issuecomment-30078910.

tpetricek commented 10 years ago

@forki Can you file a separate issue to add sorting series by something that is not a key?

tpetricek commented 10 years ago

I think we fixed all the issues (most importantly, loading of the plugin now does not require any copying).

I'm keeping this open, because it would be nice to finish the translation @forki did and publish it somewhere :-)