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.
parse_logical(x, na = c("", "NA"), locale = default_locale(), trim_ws = TRUE) parse_integer(x, na = c("", "NA"), locale = default_locale(), trim_ws = TRUE) parse_double(x, na = c("", "NA"), locale = default_locale(), trim_ws = TRUE) parse_character(x, na = c("", "NA"), locale = default_locale(), trim_ws = TRUE) col_logical() col_integer() col_double() col_character()
| x | Character vector of values to parse. |
|---|---|
| na | Character vector of strings to interpret as missing values. Set this
option to |
| locale | The locale controls defaults that vary from place to place.
The default locale is US-centric (like R), but you can use
|
| trim_ws | Should leading and trailing whitespace be trimmed from each field before parsing it? |
Other parsers: col_skip,
cols_condense, cols,
parse_datetime, parse_factor,
parse_guess, parse_number,
parse_vector
#> [1] 1 2 3#> [1] 1.000 2.000 3.123parse_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)#> Warning: 1 parsing failure. #> row col expected actual #> 4 -- a double -#> [1] 1 2 3 NA #> attr(,"problems") #> # A tibble: 1 x 4 #> row col expected actual #> <int> <int> <chr> <chr> #> 1 4 NA a double -# Or flag values as missing parse_double(x, na = "-")#> [1] 1 2 3 NA