[Rd] Feedback on a colClasses() generator function in progress?
Henrik Bengtsson
hb at stat.berkeley.edu
Thu Feb 21 18:56:22 CET 2008
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))
More information about the R-devel
mailing list