Skip to contents

Use parse_*() if you have a character vector you want to parse.

Usage

parse_logical(
  x,
  na = c("", "NA"),
  locale = default_locale(),
  trim_ws = TRUE,
  .return_problems = FALSE
)

parse_integer(
  x,
  na = c("", "NA"),
  locale = default_locale(),
  trim_ws = TRUE,
  .return_problems = FALSE
)

parse_double(
  x,
  na = c("", "NA"),
  locale = default_locale(),
  trim_ws = TRUE,
  .return_problems = FALSE
)

parse_character(
  x,
  na = c("", "NA"),
  locale = default_locale(),
  trim_ws = TRUE,
  .return_problems = FALSE
)

col_logical()

col_integer()

col_double()

col_character()

Arguments

x

Character vector of values to parse.

na

Character vector of strings to interpret as 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.

trim_ws

Should leading and trailing whitespace (ASCII spaces and tabs) be trimmed from each field before parsing it?

.return_problems

Whether to hide the problems tibble from the output

Value

a parsed vector

See also

Examples

parse_integer(c("1", "2", "3"))
#> [1] 1 2 3
parse_double(c("1", "2", "3.123"))
#> [1] 1.000 2.000 3.123
parse_number("$1,123,456.00")
#> [1] 1123456

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

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