Skip to contents

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.

Usage

as_comment_str(
  ...,
  line_width = 160L,
  comment_prefix = "# ",
  sep_paragraphs = TRUE
)

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.

Value

A character scalar.

See also

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.