Passing a seq from F# to RProvider

后端 未结 2 945
礼貌的吻别
礼貌的吻别 2020-12-22 02:22

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

相关标签:
2条回答
  • 2020-12-22 03:09

    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.

    0 讨论(0)
  • 2020-12-22 03:13

    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)
    
    0 讨论(0)
提交回复
热议问题