Build Status

captioner is an R package for generating figure numbers and captions

Installation

to install:

or if you want the vignette:

Usage

captioner() returns a captioner function for each set of figures, tables, etc. that you want to create. See the help files and vignette for more details.

For example, you can generate a full caption:

fig_nums <- captioner()
fig_nums("my_pretty_figure", "my pretty figure's caption")
#> [1] "Figure  1: my pretty figure's caption"

Or a figure number for citing:

fig_nums("my_pretty_figure", display = "cite")
#> [1] "Figure  1"

Or you can store the caption and use it in your R code chunk in markdown documents:

my_first_caption <- fig_nums("my pretty_figure", "My pretty figure's caption.")

If you create a new set of captions, perhaps for your tables, the numbering restarts:

table_nums <- captioner(prefix = "Table")
table_nums("cat_table", "A table of cat breeds.")
#> [1] "Table  1: A table of cat breeds."

You can abbreviate in text citations by using partial1 from the package pryr to create a shorter version of the function. For example:

citef <- pryr::partial(fig_nums, display = "cite")
citef("my_pretty_figure")
#> [1] "Figure  1"

Take a look at the vignette for many more details.


  1. I learned this from the glorious H Wickham and you can too