Learn R Programming

readr (version 0.2.0)

collector: Parse character vectors into typed columns.

Description

Use parse_ if you have a character vector you want to parse. Use col_ in conjunction with a read_ function to parse the values as they're read in.

Usage

parse_guess(x, na = c("", "NA"), locale = default_locale())
col_character()
parse_character(x, na = c("", "NA"), locale = default_locale())
col_integer()
parse_integer(x, na = c("", "NA"), locale = default_locale())
col_double()
parse_double(x, na = c("", "NA"), locale = default_locale())
col_euro_double()
parse_euro_double(x, na = c("", "NA"))
col_number()
parse_number(x, na = c("", "NA"), locale = default_locale())
col_logical()
parse_logical(x, na = c("", "NA"), locale = default_locale())
col_factor(levels, ordered = FALSE)
parse_factor(x, levels, ordered = FALSE, na = c("", "NA"), locale = default_locale())
col_skip()
col_guess()

Arguments

x
Character vector of values to parse.
na
Character vector of strings to use for missing values. Set this option to character() to indicate no missing values.
locale
The locale controls defaults that vary from place to place. The default locale is US-centric (like R), but you can use locale to create your own locale that controls things like the default time zone, encoding, decimal mark, big mark, and day/month names.
levels
Character vector providing set of allowed levels.
ordered
Is it an ordered factor?

See Also

parse_datetime, type_convert to automatically re-parse all character columns in a data frame.

Examples

Run this code
parse_integer(c("1", "2", "3"))
parse_double(c("1", "2", "3.123"))
parse_factor(c("a", "b"), letters)
parse_number("$1,123,456.00")

# Use locale to override default decimal and grouping marks
es_MX <- locale("es", decimal_mark = ",")
parse_number("$1.123.456,00", locale = es_MX)

# Invalid values are replaced with missing values with a warning.
x <- c("1", "2", "3", "-")
parse_double(x)
# Or flag values as missing
parse_double(x, na = "-")

Run the code above in your browser using DataLab