Type: Package
Title: Generate Comment Boxes with Custom Alignment
Version: 2.1.0
Description: Provides a function to generate comment boxes framed with '#' characters, with configurable width and text alignment (left, center, or right). Useful for formatting scripts and improving code readability.
License: MIT + file LICENSE
URL: https://gitlab.com/r-packages3/easycomment
Encoding: UTF-8
RoxygenNote: 7.3.2
Suggests: testthat (≥ 3.0.0)
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2026-04-11 10:41:52 UTC; root
Author: Gregoire Muller [aut, cre]
Maintainer: Gregoire Muller <muller.gregoire@protonmail.com>
Repository: CRAN
Date/Publication: 2026-04-11 11:00:02 UTC

Generate a Comment Box

Description

Generates a comment box framed with # characters, with configurable width and text alignment. Long words that exceed the inner width are automatically split across multiple lines.

When section_title = TRUE (the default), the top border doubles as a named RStudio code section header, so the comment text appears in the document outline instead of "Untitled". The border_style parameter offers five visual presets controlling the fill characters of the top and bottom borders.

Usage

  generate_comment_box(comment, width = 80, align = "center",
                       section_title = TRUE, border_style = "sharp",
                       print_box = TRUE)

Arguments

comment

A non-empty string containing the comment to be framed.

width

The total width of the comment box in characters. Must be greater than 4. Default is 80.

align

The alignment of the text inside the box. One of "left", "center", or "right". Default is "center".

section_title

Logical. If TRUE (default), the top border is formatted as a named RStudio section header so that the document outline displays the comment text rather than "Untitled". The bottom border uses a non-triggering fill character (controlled by border_style) to prevent RStudio from creating a spurious "Untitled" section. If FALSE, both borders are plain # lines, preserving the original behaviour; border_style is then ignored.

border_style

Character string selecting the fill characters for the top and bottom borders when section_title = TRUE. Ignored when section_title = FALSE. Available styles:

Name Top Bottom
"sharp" # /
"double" = /
"light" - ~
"soft" = ~
"wave" # ~

The top character must be one of #, -, or = so that RStudio detects the line as a named section. The bottom character must be none of those to avoid creating an "Untitled" section. Default is "sharp".

print_box

Logical. If TRUE, the comment box is printed to the console and returned invisibly. If FALSE, the box is returned as a character string. Default is TRUE.

Value

If print_box is TRUE, prints the comment box to the console and returns it invisibly as a character string.

If print_box is FALSE, returns the comment box as a single character string with newline characters (\n) separating each row.

Examples

  # Style par défaut (sharp) : # en haut, / en bas
  generate_comment_box("Chargement des données")

  # Style double : = en haut, / en bas
  generate_comment_box("Modélisation", border_style = "double")

  # Style light : - en haut, ~ en bas, aligné à gauche
  generate_comment_box("Paramètres", border_style = "light", align = "left")

  # Style soft : = en haut, ~ en bas
  generate_comment_box("Résultats", border_style = "soft")

  # Style wave : # en haut, ~ en bas
  generate_comment_box("Exports", border_style = "wave")

  # Comportement d'origine : deux bordures pleines de #
  generate_comment_box("Legacy box", section_title = FALSE)