as_str: Convert to a character scalar (aka string)

as_strR Documentation

Convert to a character scalar (aka string)

Description

Similar to paste0(..., collapse = ""), but recursively converts its inputs to type character.

Usage

as_str(..., sep = "", rm_na = FALSE)

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.

Value

A character scalar.

See Also

Other string functions: as_chr(), as_comment_str(), as_line_feed_chr(), capitalize_first(), dsv_colnames(), enum_str(), escape_lf(), fuse_regex(), prettify_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 = "")

# ...this one works harder
pal::as_str(input)

salim-b/pal documentation built on Feb. 28, 2025, 6:51 p.m.