Takes a vector of paragraphs, wraps them at the specified line width, prefixes them with comment markers and returns the result as a single string.
Arguments
- ...
Comment lines. A character vector or something coercible to.
- line_width
Maximum character width at which to wrap lines. A positive integerish scalar.
- comment_prefix
Character sequence that indicates the start of a comment. A character scalar.
- sep_paragraphs
Whether or not to separate paragraphs with an empty comment line.
See also
Other string functions:
as_chr()
,
as_line_feed_chr()
,
as_str()
,
capitalize_first()
,
dsv_colnames()
,
enum_str()
,
escape_lf()
,
fuse_regex()
,
prettify_nr()
,
prose_ls()
,
sentenceify()
,
wrap_chr()
Examples
pal::as_comment_str(glue::glue("Copyright (C) {format(Sys.Date(), '%Y')} Santa Clause"),
"No presents without code.") |>
cat()
#> # Copyright (C) 2024 Santa Clause
#> #
#> # No presents without code.
# wrap lines at 20 chars
pal::as_comment_str(glue::glue("Copyright (C) {format(Sys.Date(), '%Y')} Santa Clause"),
"No presents without code.",
line_width = 20L) |>
cat()
#> # Copyright (C) 2024
#> # Santa Clause
#> #
#> # No presents
#> # without code.
# disable empty comment lines between paragraphs:
pal::as_comment_str(glue::glue("Copyright (C) {format(Sys.Date(), '%Y')} Santa Clause"),
"Hohoho.",
sep_paragraphs = FALSE) |>
cat()
#> # Copyright (C) 2024 Santa Clause
#> # Hohoho.