Skip to contents

Recursively applies base::as.character() to its inputs.

Usage

as_chr(..., use_names = FALSE)

Arguments

...

R objects to be converted to a character vector. Dynamic dots are supported.

use_names

Whether or not to preserve names by base::unlist().

Value

A character vector.

Examples

library(magrittr)

to_convert <-
  list(tibble::tibble(a = 1:3), "A", factor("wonderful"), xfun::strict_list("day")) %T>%
  print()
#> [[1]]
#> # A tibble: 3 × 1
#>       a
#>   <int>
#> 1     1
#> 2     2
#> 3     3
#> 
#> [[2]]
#> [1] "A"
#> 
#> [[3]]
#> [1] wonderful
#> Levels: wonderful
#> 
#> [[4]]
#> [[1]]
#> [1] "day"
#> 
#> 

as.character(to_convert)
#> [1] "list(a = 1:3)" "A"             "1"             "list(\"day\")"
pal::as_chr(!!!to_convert)
#> [1] "1"         "2"         "3"         "A"         "wonderful" "day"