R readr single col_types
Is it possible in a package readr
to read data and specify the same data type for all columns? Likewise base::read.table
with colClasses = "character"
or using an argument as.is
.
If the task, data headers, file encoding, etc. not predefined, I prefer to write my loaders without changing data types and then process the schema later. Always be open to guesswork about how other people think about things.
source to share
Converting my comment to answer. No, it is not built in (at the moment), the documentation col_types
is quite clear regarding its capabilities, this is not one of them. Given the way col_types
, it will probably need a new argument to implement this, since the function is to use "short" to limit the number of columns read col_types
.
However, you can write a shell:
read_table_asis = function(...) {
n_cols = ncol(read_table(..., n_max = 1))
read_table(..., col_types = paste(rep("c", n_cols), collapse = ""))
}
source to share