Create caption

as.caption(
  x,
  short = NULL,
  short_repeat = TRUE,
  short_sep = NULL,
  write = FALSE
)

Arguments

x

caption text.

short

an abbreviated form of the caption to be used in a list of tables.

short_repeat

logical; if a short caption is provided, it will be repeated at the start of the main caption.

short_sep

a character sequence used to separate the short title with the main caption when a short title is specified.

write

logical; if TRUE, caption will be written to output file when stable_save() is called; this argument does not apply to stable_long objects whose captions are always written to output the output file.

Value

An object inheriting from st_caption and character.

Details

Caption text (in x) can contain a short caption title enclosed in brackets ([]) as the opening characters (see examples). The short title is assumed to start after the opening [ and end prior to ] when all brackets are matched, allowing [...] in the short title as long as all brackets are matched. For other scenarios where a single ] may need to appear in the short title, the user should use the short argument instead of the bracket notation.

Examples


# No separate short title
as.caption("Main title text")
#> [1] "Main title text"

# Note that the short title is repeated by default
as.caption("[Short title]. Main title text")
#> [1] "[Short title] Short title. Main title text"

unclass(as.caption("[Short title]. Main title text."))
#> [1] "Short title. Main title text."
#> attr(,"short")
#> [1] "Short title"
#> attr(,"write")
#> [1] FALSE
unclass(as.caption(". Main title text.", short = "Short"))
#> [1] "Short. Main title text."
#> attr(,"short")
#> [1] "Short"
#> attr(,"write")
#> [1] FALSE