knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
acronymr is an R package to facilitate the use of acronyms in rmarkdown documents. Acronyms and their definitions are stored in a data frame which are then referenced inline to place the formatted acronym in the rendered document. Initial use of an acronym will define the acronym while subsequent use will just place the acronym. Options are available to use the plural form, an alternate form which may include special formatting such as italics or super and subscripts, or the definition.
acronymr tracks which acronyms are used and provides a function to return a data frame of used acronyms suitable for output in a table.
You can install acronymr from github with:
# install.packages("devtools") devtools::install_github("HJAllen/acronymr")
A data frame with acronyms and definitions provided by the user:
library(acronymr) acronyms <- # Create acronyms lookup table tibble::tribble( ~Acronym, ~Alternate, ~Definition, "GMO", NA, "Genetically Modified Organism", 'IMO', NA,'In My Opinion', 'PCR', NA, 'Polymerase Chain Reaction', 'DNA', NA, 'Deoxyribonucleic Acid', 'H2NO3', 'H~2~NO~3~', 'Nitric Acid') # Add inclusion flag acronyms$Include <- FALSE # Alphabetize acronyms for ease of reading acronyms <- acronyms[order(acronyms$Acronym),] acronyms
The function ac
will insert the formatted acronym. When an acronym is used, if acronyms$Include
is set to FALSE
indicating first usage, the return value is the long form of the acronym followed by either the acronym name or alternate form depending on altFrm
. Plural forms can be generated using the parameter p
. Subsequent uses of the acronym will return the acronym formatted as requested.
The following:
The `r
ac("DNA")`
of a `r
ac("GMO")`
has been modified. `r
ac("PCR")`
can be used to characterize `r
ac("DNA")`
in `r
ac("GMO", p = TRUE)`
. Be careful to avoid introduction of `r
ac("H2NO3", altFrm = TRUE)`
.
Produces:
The r ac("DNA")
of a r ac("GMO")
has been modified. r ac("PCR")
can be used to characterize r ac("DNA")
in r ac("GMO", p = TRUE)
. Be careful to avoid introduction of r ac("H2NO3", altFrm = TRUE)
.
There are instances when the long form of the acronym is needed such as section headings: `r
ac("GMO", lngFrm = TRUE)`
.
r ac("GMO", lngFrm = TRUE)
When an acronym is used, acronyms$Include
is updated to TRUE
and a data frame containing used acronyms suitable for table generation is returned by acTable
:
acTable("acronyms", altFrm = TRUE) knitr::kable(acTable("acronyms"), caption = "*Table 1.* Acronyms Used.")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.