Similar to paste0(..., collapse = ""), but recursively converts its inputs to type character.
Arguments
- ...
R objects to be assembled to a single string. Dynamic dots are supported.
- sep
Separator to delimit
.... Defaults to none ("").- rm_na
Exclude missing values. If
FALSE, missing values will be represented as"NA"in the resulting string.
See also
Other string functions:
as_chr(),
as_comment_str(),
as_env_var_name(),
as_line_feed_chr(),
capitalize_first(),
dsv_colnames(),
enum_str(),
escape_lf(),
fuse_regex(),
phrase_nr(),
sentenceify(),
wrap_chr()
Examples
library(magrittr)
input <-
paste0(2:4,
collapse = ", ") |>
purrr::map(rep,
times = 20) %>%
list(c("This is a glut of ", "meaningless numbers: "), .)
# while this just converts `input` in a lazy way...
paste0(input,
collapse = "")
#> [1] "c(\"This is a glut of \", \"meaningless numbers: \")list(c(\"2, 3, 4\", \"2, 3, 4\", \"2, 3, 4\", \"2, 3, 4\", \"2, 3, 4\", \"2, 3, 4\", \"2, 3, 4\", \"2, 3, 4\", \"2, 3, 4\", \"2, 3, 4\", \"2, 3, 4\", \"2, 3, 4\", \"2, 3, 4\", \"2, 3, 4\", \"2, 3, 4\", \"2, 3, 4\", \"2, 3, 4\", \"2, 3, 4\", \"2, 3, 4\", \"2, 3, 4\"))"
# ...this one works harder
pal::as_str(input)
#> [1] "This is a glut of meaningless numbers: 2, 3, 42, 3, 42, 3, 42, 3, 42, 3, 42, 3, 42, 3, 42, 3, 42, 3, 42, 3, 42, 3, 42, 3, 42, 3, 42, 3, 42, 3, 42, 3, 42, 3, 42, 3, 42, 3, 42, 3, 4"
