I asked this question last week regarding seq
values passed to RProvider. I had hoped that I\'d be able to apply the accepted answer there
You can use Option.toObj
.
For example:
let l1 = [ Some "x"; None; Some "y"]
let l2 = l1 |> List.map (Option.toObj)
// val l2 : string list = ["x"; null; "y"]
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.
Edit : Option.ofObj
does work properly. F# Interactive displays None
as null
when it is in a list for some reason.
The answer to your previous question is still applicable. You can use null
to indicate a missing string value:
let optString = ["x"; null; "y"]
let testData5 =
namedParams [
"optString", optString;]
|> R.data_frame
Gives me:
val testData5 : SymbolicExpression =
optString
1 x
2<NA>
3 y
You can convert the option string to just string list:
let optString2 = [Some "x"; None; Some "y"]
optString2
|> List.map (fun x -> match x with
| Some x -> x
| None -> null)