传递seq< string option>从F#到RProvider [英] Passing a seq<string option> from F# to RProvider
问题描述
我上周问此问题关于option
类型.不幸的是,NaN
仅适用于R中的numeric
.
I asked this question last week regarding seq<float option>
values passed to RProvider. I had hoped that I'd be able to apply the accepted answer there to other option
types in F#. Unfortunately, NaN
is only applicable to numeric
in R.
如何将F#中的None
字符串转换为NA
并传递给R?
How can I convert a None
string in F# to NA
and pass to R?
推荐答案
您可以使用Option.toObj
.
例如:
let l1 = [ Some "x"; None; Some "y"]
let l2 = l1 |> List.map (Option.toObj)
// val l2 : string list = ["x"; null; "y"]
并且您可以将Option.toNullable
用于数字值,但是它将转换为类型Nullable<float>
,而None
也将是null
. 由于某种原因,这反过来又行不通:
And you can use Option.toNullable
for number values, but it would convert to type Nullable<float>
, and None
would also be null
. For some reason this doesn't work the other way round:
let l3 = l2 |> List.map (Option.ofObj)
// val l3 : string option list = [Some "x"; null; Some "y"]
我不知道这是故意还是错误.
I don't know if that's intended or a bug.
Option.ofObj
可以正常工作.由于某些原因,F#Interactive在列表中将None
显示为null
.
Edit : Option.ofObj
does work properly. F# Interactive displays None
as null
when it is in a list for some reason.
这篇关于传递seq< string option>从F#到RProvider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!