Learn R Programming

ufs (version 0.5.12)

insertFigureCaption: Insert numbered caption

Description

These functions can be used to manually insert a numbered caption. These functions have been designed to work well with setFigCapNumbering() and setTabCapNumbering(). This is useful when inserting figures or tables in an RMarkdown document when you use automatic caption numbering for knitr chunks, but are inserting a table or figure that isn't produced in a knitr chunk while still retaining the automatic numbering. insertNumberedCaption() is the general-purpose function; you will typically only use insertFigureCaption() and insertTableCaption().

Usage

insertFigureCaption(
  captionText = "",
  captionName = "fig.cap",
  prefix = getOption(paste0(optionName, "_prefix"), "Figure %s: "),
  suffix = getOption(paste0(optionName, "_suffix"), ""),
  optionName = paste0("setCaptionNumbering_", captionName),
  resetCounterTo = NULL
)

insertNumberedCaption( captionText = "", captionName = "fig.cap", prefix = getOption(paste0(optionName, "_prefix"), "Figure %s: "), suffix = getOption(paste0(optionName, "_suffix"), ""), optionName = paste0("setCaptionNumbering_", captionName), resetCounterTo = NULL )

insertTableCaption( captionText = "", captionName = "tab.cap", prefix = getOption(paste0(optionName, "_prefix"), "Table %s: "), suffix = getOption(paste0(optionName, "_suffix"), ""), optionName = paste0("setCaptionNumbering_", captionName), resetCounterTo = NULL )

Value

The caption in a character vector.

Arguments

captionText

The text of the caption.

captionName

The name of the caption; by default, for tables, "tab.cap".

prefix, suffix

The prefix and suffix texts; base::sprintf() is used to insert the number in the position taken up by \%s.

optionName

The name of the option to use to save the number counter.

resetCounterTo

If a numeric value, the counter is reset to that value.

Examples

Run this code
insertNumberedCaption("First caption");
insertNumberedCaption("Second caption");
sectionNumber <- 12;
insertNumberedCaption("Third caption",
                      prefix = paste0("Table ",
                                      sectionNumber,
                                      ".%s: "));

Run the code above in your browser using DataLab