ac: Acronym handling function

Description Usage Arguments Details Value Examples

View source: R/acronymr.R

Description

ac formats acronyms when called inline in rmarkdown.

Usage

1
2
ac(acronym = NULL, acronyms = "acronyms", p = FALSE,
  altFrm = FALSE, lngFrm = FALSE)

Arguments

acronym

character string matching value in Acronym column of acronyms

acronyms

character string containing name of acronym data frame

p

logical indicating if the acronym is plural

altFrm

logical indicating if alternate form of acronym should be used

lngFrm

logical indicating if long form of acronym should be used

Details

ac handles inline acronyms and references a dataframe with the acronym name, alternate formatting, definition and include flag and returns a character string. Options include whether the acronym usage is singular or plural and whether the full definition should be used. The function handles missing acronyms, checks for first time usage, and formats the return accordingly. This function is most commonly used in rmarkdown documents.

The acronyms data frame must contain the following columns:

Value

When an acronym is used, the acronym entry is found in acronmys and if 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 enclosed in parentheses. acronyms$Include is set to TRUE. Subsequent usage of an acronym will return the acronym name or alternate form.

If acronyms is not found or if acronyms exists but is not a data frame or does not include the necessary columns, the function stops and issues an error. If the acronym is not found in acronyms a warning is issued and XXXacro:Acronym Not DefinedXXX is returned.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# Example acronyms data frame
acronyms <-
  tibble::tribble(
    ~Acronym, ~Alternate, ~Definition,
    "IMO", NA,"In My Opinion",
    "PCR", NA, "Polymerase Chain Reaction",
    "RNA", NA, "Ribonucleic 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),]

# inline usage
ac(acronym = "IMO", acronyms = "acronyms", p = FALSE, altFrm = FALSE, lngFrm = FALSE)
# or simply
ac("IMO")

HJAllen/acronymr documentation built on Dec. 26, 2019, 9:26 a.m.