R API Suggestion: Return date fields as dates, not factors | Peter | 2010-04-08 18:31 |
Status: Closed | ||
Ben, Not sure which version of Rlabkey you're using, but the latest v 2.1.112 has been released on CRAN. I'm pretty sure it always returns non-factor columns from selectRows, getRows and executeSql. I tried it just now on a table with date field and this is what I'm getting: > library(Rlabkey) Loading required package: RCurl Loading required package: bitops Loading required package: rjson > s<- getSession("http://localhost:8080/labkey", "/apisamples") > sc <- getSchema(s,"lists") > r<- getRows(s, sc$AllTypes) > str(r) 'data.frame': 10 obs. of 11 variables: $ DisplayFld : chr "Row 1" "Row 2 Empty Vals" "Row 3 (plain)" "row 4 (the n word)" ... $ TextFld : chr "some text here" NA "More plane values" "null NULL NA and na" ... $ IntFld : num 99 NA -34 123 NA NA 777 98 98 98 $ DoubleFld : num 987.7 NA 98123.4 44.3 NA ... $ DateTimeFld :Class 'Date' num [1:10] 14654 NA 10592 11738 NA ... $ BooleanFld : logi FALSE FALSE FALSE FALSE FALSE FALSE ... $ LongTextFld : chr "Could be some very long text" NA "The quick brown fox jumped over the fence. The quick brown fox jumped over the fence. The quick brown fox jumped over the fen"| __truncated__ NA ... $ AttachmentFld: chr "PlainTextDoc.txt" NA NA NA ... $ RequiredText : chr "I have to fill this out" "Cannot be empty" "no attachment" "lots of words for empty" ... $ RequiredInt : num 42 55 88 456 1 2 0 0 0 0 $ Category : chr "PLAIN" NA "PLAIN" "EMPTY" ... > is.factor(r$DateTimeFld) [1] FALSE > r1<- cbind(r[, 1:4], factor(r[, 5]), r[,6:11]) > str(r1) 'data.frame': 10 obs. of 11 variables: $ DisplayFld : chr "Row 1" "Row 2 Empty Vals" "Row 3 (plain)" "row 4 (the n word)" ... $ TextFld : chr "some text here" NA "More plane values" "null NULL NA and na" ... $ IntFld : num 99 NA -34 123 NA NA 777 98 98 98 $ DoubleFld : num 987.7 NA 98123.4 44.3 NA ... $ factor(r[, 5]): Factor w/ 4 levels "1999-01-01","2002-02-20",..: 3 NA 1 2 NA NA 4 4 4 4 $ BooleanFld : logi FALSE FALSE FALSE FALSE FALSE FALSE ... $ LongTextFld : chr "Could be some very long text" NA "The quick brown fox jumped over the fence. The quick brown fox jumped over the fence. The quick brown fox jumped over the fen"| __truncated__ NA ... $ AttachmentFld : chr "PlainTextDoc.txt" NA NA NA ... $ RequiredText : chr "I have to fill this out" "Cannot be empty" "no attachment" "lots of words for empty" ... $ RequiredInt : num 42 55 88 456 1 2 0 0 0 0 $ Category : chr "PLAIN" NA "PLAIN" "EMPTY" ... > is.factor(r1[,5]) [1] TRUE Let me know if the update fixes your situation. Also check out the new Vignette and the major speed increase. |
||