传递 seq<string option>从 F# 到 RProvider [英] Passing a seq&lt;string option&gt; from F# to RProvider

查看:23
本文介绍了传递 seq<string option>从 F# 到 RProvider的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我上周问了这个问题关于seq 传递给 RProvider 的值.我曾希望我能够将那里接受的答案应用于 F# 中的其他 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,并且 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆