Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

cols

Create column specification


Description

cols() includes all columns in the input data, guessing the column types as the default. cols_only() includes only the columns you explicitly specify, skipping the rest.

Usage

cols(..., .default = col_guess(), .delim = NULL)

cols_only(...)

col_logical(...)

col_integer(...)

col_big_integer(...)

col_double(...)

col_character(...)

col_skip(...)

col_number(...)

col_guess(...)

col_factor(levels = NULL, ordered = FALSE, include_na = FALSE, ...)

col_datetime(format = "", ...)

col_date(format = "", ...)

col_time(format = "", ...)

Arguments

...

Either column objects created by col_*(), or their abbreviated character names (as described in the col_types argument of vroom()). If you're only overriding a few columns, it's best to refer to columns by name. If not named, the column types must match the column names exactly. In col_*() functions these are stored in the object.

.default

Any named columns not explicitly overridden in ... will be read with this column type.

.delim

The delimiter to use when parsing. If the delim argument used in the call to vroom() it takes precedence over the one specified in col_types.

levels

Character vector providing set of allowed levels. if NULL, will generate levels based on the unique values of x, ordered by order of appearance in x.

ordered

Is it an ordered factor?

include_na

If NA are present, include as an explicit factor to level?

format

A format specification, as described below. If set to "", date times are parsed as ISO8601, dates and times used the date and time formats specified in the locale().

Unlike strptime(), the format specification must match the complete string.

Details

The available specifications are: (with string abbreviations in brackets)

  • col_logical() [l], containing only T, F, TRUE or FALSE.

  • col_integer() [i], integers.

  • col_big_integer() [I], Big Integers (64bit), requires the bit64 package.

  • col_double() [d], doubles.

  • col_character() [c], everything else.

  • col_factor(levels, ordered) [f], a fixed set of values.

  • col_date(format = "") [D]: with the locale's date_format.

  • col_time(format = "") [t]: with the locale's time_format.

  • col_datetime(format = "") [T]: ISO8601 date times

  • col_number() [n], numbers containing the grouping_mark

  • col_skip() [_, -], don't import this column.

  • col_guess() [?], parse using the "best" type based on the input.

Examples

cols(a = col_integer())
cols_only(a = col_integer())

# You can also use the standard abbreviations
cols(a = "i")
cols(a = "i", b = "d", c = "_")

# You can also use multiple sets of column definitions by combining
# them like so:

t1 <- cols(
  column_one = col_integer(),
  column_two = col_number())

t2 <- cols(
 column_three = col_character())

t3 <- t1
t3$cols <- c(t1$cols, t2$cols)
t3

vroom

Read and Write Rectangular Text Data Quickly

v1.4.0
GPL-3
Authors
Jim Hester [aut, cre] (<https://orcid.org/0000-0002-2739-7082>), Hadley Wickham [aut] (<https://orcid.org/0000-0003-4757-117X>), https://github.com/mandreyel/ [cph] (mio library), R Core Team [ctb] (localtime.c code adapted from R), Jukka Jylänki [cph] (grisu3 implementation), Mikkel Jørgensen [cph] (grisu3 implementation), RStudio [cph, fnd]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.