【发布时间】:2017-01-21 15:21:11
【问题描述】:
似乎RTypeProvider 只能处理相同类型的namedParams。是这样吗?
例如,
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
不起作用,因为我在 x.Qty 上收到错误提示
This expression was expected to have type
string
but here has type
float option
如果我在thingForR let 中颠倒顺序,则会得到相反的错误:
let thingForR =
namedParams [
"qty", someFoos |> List.map (fun x -> x.Qty);
"which", someFoos |> List.map (fun x -> x.Which);
]
|> R.data_frame
这里,x.Which 的错误是
This expression was expected to have type
float option
but here has type
string
namedParams中的字典不能有不同的类型吗?如果是这样,您如何在 F# 中创建具有不同类型的数据框并将它们传递给 R?
【问题讨论】:
-
这是一个 F# 错误,欢迎使用强类型语言 :-) 你需要
box它。但是您也会遇到选项类型的问题。我不知道为什么,但没有转换器。让我先搜索一下相关答案。
标签: r f# type-providers