as_comment_str: Assemble an (R) comment string of the desired line width

as_comment_strR Documentation

Assemble an (R) comment string of the desired line width

Description

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

Other string functions: as_chr(), as_line_feed_chr(), as_str(), capitalize_first(), dsv_colnames(), enum_str(), escape_lf(), fuse_regex(), prettify_nr(), sentenceify(), wrap_chr()

Examples

pal::as_comment_str(glue::glue("Copyright (C) {format(Sys.Date(), '%Y')} Santa Clause"),
                    "No presents without code.") |>
  cat()

# 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()

# 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()

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