Is it possible within readr
package to read in data and specify a single data type across all columns? Similar to base::read.table
with colClasses = "character"
or using the as.is
argument.
Unless the task, data headers, file encoding, etc are well defined ahead of analysis I prefer to write my loaders without changing the datatypes and then process the schema later downstream. Always open to suggestion on how other folks think about things.
As of readr 0.2.2 we can do something like this to read a csv with all columns as character:
read_csv("path/to/file",col_types = cols(.default = col_character()))
Converting my comment to answer. No, this isn't built-in (at this point), the documentation of the col_types
is quite clear about its capabilities, this isn't one of them. Given the way col_types
works, implementing this would probably require a brand new argument since a feature is that a "short" col_types
will be used to restrict the number of columns read.
However, you could write a wrapper:
read_table_asis = function(...) {
n_cols = ncol(read_table(..., n_max = 1))
read_table(..., col_types = paste(rep("c", n_cols), collapse = ""))
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With