2016-09-13 1 views
1

RTypeProvider은 같은 유형의 namedParams 만 처리 할 수 ​​있습니다. 이 경우인가요? 예를 들어RTypeProvider를 사용하여 여러 유형의 데이터 프레임을 만드는 방법

, 나는 thingForR하자의 순서를 반대로하면 내가

This expression was expected to have type 
    string 
but here has type 
    float option 

을 말하는 x.Qty에 오류가로

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 

이 작동하지 않습니다, 나는 반대 오류 :

let thingForR = 
    namedParams [ 
     "qty", someFoos |> List.map (fun x -> x.Qty); 
     "which", someFoos |> List.map (fun x -> x.Which); 
     ] 
    |> R.data_frame 

여기에서의 오류은

This expression was expected to have type 
    float option 
but here has type 
    string 

namedParams의 사전에는 다른 유형이 없을 수 있습니까? 그렇다면 F #에서 다른 유형의 데이터 프레임을 만들고이를 R로 전달하는 방법은 무엇입니까?

+0

강하게 언어 입력에 오신 것을 환영합니다. 그러나 옵션 유형에도 문제가 있습니다. 왜 그런지 모르지만 변환기가 없습니다. 먼저 관련 답변을 검색하겠습니다. – s952163

답변

0

사전에 값을 입력해야합니다. 그런 식으로 그들은 모두 단지 대상이됩니다. 그래서 :

let thingForR = 
    namedParams [ 
     "which", box (someFoos |> List.map (fun x -> x.Which)); 
     "qty", box (someFoos |> List.map (fun x -> x.Qty) |> List.map (Option.toNullable >> float)); 
     ] 
    |> R.data_frame 

저를 제공합니다

val thingForR :
SymbolicExpression = which qty
1 that 4
2 other 2

Option listfloat list에 변환 할 float option에 이전 질문을 참조하십시오. 또한 필요한 경우 string option.

(없는 경우 옵션 값) 당신은 Deedle를 통해 갈 수 있습니다 : 당신이`를 box` 필요 :-)

F 번호 오류의
let someFoos' = [{Which = "that"; Qty = 4.0}; {Which = "other"; Qty = 2.0}] 
let df' = someFoos' |> Frame.ofRecords 
df' |> R.data_frame 
+0

여러 맵과 옵션 변환이 엉망인 것처럼 보일 수도 있지만 사실 많이 사용하면 헬퍼 함수를 ​​정의하게됩니다. – s952163

+0

아하! 완전한. 감사. 그리고 'float 옵션'을'NaN '으로 변환하는 것은'string 옵션'을'null'로 변환하는 것처럼 필요합니다. 이 질문으로 물건을 어지럽히 지 않기로 결정했습니다. – Steven