Henrik Bengtsson
2008-Feb-21 17:56 UTC
[Rd] Feedback on a colClasses() generator function in progress?
I'm working on colClasses() function that generates "colClasses" vectors for read.table() using a compact format string (see below). The below is what I got right now. Before adding it to R.utils, I would like to check with you if I'm missing something obvious such as certain column classes, if there are use cases it cannot handle, or if there is another way to achieve the same. I appreciate any feedback. Cheers Henrik library(R.oo) source("http://www.braju.com/R/tmp/colClasses.R") # All predefined types print(colClasses("-?cdfilnrzDP")) ## [1] "NULL" "NA" "character" "double" ## [5] "factor" "integer" "logical" "numeric" ## [9] "raw" "complex" "Date" "POSIXct" # A string in column 1, integers in column 4 and 5, rest skipped print(colClasses("c--ii----")) ## [1] "character" "NULL" "NULL" "integer" ## [5] "integer" "NULL" "NULL" "NULL" ## [9] "NULL" # Repeats and custom column classes c1 <- colClasses("3c{MyClass}3{foo}") print(c1) ## [1] "character" "character" "character" "MyClass" ## [5] "foo" "foo" "foo" # Passing repeats and class names using sprintf() syntax c2 <- colClasses("%dc{%s}%d{foo}", 3, "MyClass", 3) stopifnot(identical(c1, c2))
Possibly Parallel Threads
- Any way to get read.table.ffdf() (in the ff package) to pass colClasses or comment.char parameters through to read.fwf() ?
- extending the colClasses argument in read.table
- A couple of issues with colClasses/setAs
- read.table(..., header == FALSE, colClasses = <vector with names attribute>)
- colClasses: supressed 'NA'