banner: Make a decorated comment in an R script

Description Usage Arguments Value Functions Examples

View source: R/banner.R

Description

Make a decorated multi-line comment from input strings and, if possible, transfer it to the clipboard ready for pasting into an R script (via the print method).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
banner(
  x,
  ...,
  emph = FALSE,
  snug = FALSE,
  upper = emph,
  centre = !fold,
  leftSideHashes = 2 + emph,
  rightSideHashes = leftSideHashes,
  minHashes = (!snug) * (65 + 10 * emph),
  numLines = 1 + emph,
  bandChar = "#",
  center = centre,
  fold = FALSE,
  maxChar = 75
)

section(..., emph = TRUE, centre = TRUE, fold = TRUE)

boxup(..., rightSideHashes = 1, bandChar = "-")

open_box(
  ...,
  minHashes = 0,
  rightSideHashes = 0,
  centre = FALSE,
  bandChar = "-",
  center
)

block(
  ...,
  leftSideHashes = 3,
  rightSideHashes = 0,
  centre = FALSE,
  minHashes = 0,
  numLines = 0,
  center
)

Arguments

x

A string, first line of the comment. If "", the zero-length string, only the top lines of the banner are made. If missing, in an interactive session the user will be prompted for the input strings, one per line, in the console.

...

Zero or more additional strings as extra lines. Strings may contain newline characters resulting in further line breaks.

emph

A logical value: Do you want this to be an emphasised comment?

snug

A logical value: Do you want the decoration to hug the strings closely?

upper

A logical value: Do you want the strings converted to upper case?

centre

A logical value: Do you want the text strings centred? (alternative: left justified)

leftSideHashes

A positive integer: How many hashes go on the left side?

rightSideHashes

A non-negative integer: How many hashes go on the right side?

minHashes

A non-negative integer: What is the minimum number of hashes in the boundary lines?

numLines

A non-negative integer: How many lines of hashes above and below do you want?

bandChar

A single character. Used instead of # for all characters in the bands around the text, apart from the first character of every line.

center

Alternative spelling of centre.

fold

Logical: should the text be folded to ensure lines are not too long?

maxChar

Ingeter: maximum length allowed in any line if fold is TRUE.

Value

A character string vector returned invisibly, but automatically displayed in the console

Functions

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
banner("This should appear clearly and stand out.",
       "The lines are left justified by default.")
section("This is the first line in a section heading",
        "and this is the second\nand this the third.")
boxup("This is a less obtrusive comment",
      "centred on multiple lines", center = TRUE, bandChar = ".")
banner("This is an important side issue.", "Take note!",
      snug = TRUE, bandChar = "=")
open_box("This is a succinctly presented comment",
         "left justified and open at the right",
         "on multiple lines")

block("This is a chatty comment.  Entering it this way just",
      "saves a tiny bit of typing but it can be useful if",
      "you need multiple initial hash marks, as you may when",
      "using Emacs/ESS, for example.",
      "Or if you want the lines centred for some odd reason.",
      center = TRUE)
## some authors like to use lines of a uniform length to separate code sections:
boxup("")

Example output

sh: 1: cannot create /dev/null: Permission denied

#################################################################
##          This should appear clearly and stand out.          ##
##          The lines are left justified by default.           ##
#################################################################

sh: 1: cannot create /dev/null: Permission denied

###########################################################################
###########################################################################
###                                                                     ###
###             THIS IS THE FIRST LINE IN A SECTION HEADING             ###
###                        AND THIS IS THE SECOND                       ###
###                         AND THIS THE THIRD.                         ###
###                                                                     ###
###########################################################################
###########################################################################

sh: 1: cannot create /dev/null: Permission denied

##................................................................
##                This is a less obtrusive comment               .
##                   centred on multiple lines                   .
##................................................................

sh: 1: cannot create /dev/null: Permission denied

##======================================
##  This is an important side issue.  ==
##             Take note!             ==
##======================================

sh: 1: cannot create /dev/null: Permission denied

##------------------------------------------
##  This is a succinctly presented comment  
##  left justified and open at the right    
##  on multiple lines                       
##------------------------------------------

sh: 1: cannot create /dev/null: Permission denied

###  This is a chatty comment.  Entering it this way just        
###  saves a tiny bit of typing but it can be useful if          
###  you need multiple initial hash marks, as you may when       
###  using Emacs/ESS, for example.                               
###  Or if you want the lines centred for some odd reason.       

sh: 1: cannot create /dev/null: Permission denied

##----------------------------------------------------------------

bannerCommenter documentation built on March 23, 2021, 9:06 a.m.