How to create a data frame of several types using RTypeProvider

It seems that it RTypeProvidercan only process namedParamsthe same type. This is true?

For instance,

open RDotNet
open RProvider 

type foo = {
    Which: string
    Qty: float option
    }    

let someFoos = [{Which = "that"; Qty = Some 4.0}; {Which = "other"; Qty = Some 2.0}]

let thingForR = 
    namedParams [
        "which", someFoos |> List.map (fun x -> x.Which); 
        "qty", someFoos |> List.map (fun x -> x.Qty);
        ]
    |> R.data_frame

not working since I get an error x.Qty

This expression was expected to have type 
  string
but here has type
  float option

If I thingForRreverse the order in let, then I get the opposite error:

let thingForR = 
    namedParams [
        "qty", someFoos |> List.map (fun x -> x.Qty); 
        "which", someFoos |> List.map (fun x -> x.Which);
        ]
    |> R.data_frame

Here the error x.Whichis not equal to

This expression was expected to have type
  float option
but here has type
  string

Can a dictionary in namedParamsnot have different types? If so, how can you create a data frame with different types in F # and pass them to R?

+1
source share
1 answer

You need to insert the values ​​inside the dictionary. Thus, they are all just objective. So:

let thingForR = 
    namedParams [
        "which", box (someFoos |>  List.map (fun x ->  x.Which) ); 
        "qty", box  (someFoos |> List.map (fun x ->   x.Qty) |> List.map (Option.toNullable >> float));
        ]
    |> R.data_frame

gives me:

val thingForR:
=, qty
1, 4
2 2

float, Option list float list. , .

Deedle ( ):

let someFoos' = [{Which = "that"; Qty =  4.0}; {Which = "other"; Qty =  2.0}]
let df' = someFoos' |> Frame.ofRecords
df' |> R.data_frame 
0

Source: https://habr.com/ru/post/1662577/


All Articles