Site icon R-bloggers

add abbreviations to your rmarkdown doc

[This article was first published on Category R on Roel's R-tefacts, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Today a small tip for when you write rmarkdown documents. Add a chunk on top with abbreviations.

in the first chunks you set the options and load the packages. Next create abbreviations, you don’t have to care about the ordering, just put them down as you realize you are creating them.

The first step makes a dataframe (a tibble, rowwise), and the second step orders them.

tribble(
    ~Abbreviation, ~ Explanation,
    "CIA", "Central Intelligence Agency",
    "dplyr", "data.frame plyr, a tool for working with data in a rectangular format",
    "ABC", "The first few letters of the alphabet"
) %>%
    arrange(Abbreviation)

If you make use of many abbreviations, you might want to put them all in a dataframe and add them to your document.

Even better: add them to a package: a dataframe with all your abbreviations, a template rmarkdown document with your company logos, and perhaps some ggplot themes to style your corporate work.

For instance: I create an enourmous collection of obscure abbreviations in use in my company and put them all in my package. You don’t want to use them all in your document, that would be silly. You only want to explain the abbreviations that you use in the document.

library(tidyverse)
library(your_corp_package)
all_abbreviations_used <- c("CIA", "DONKLEBODY", "WUT", "SPEEDR")
abbreviations %>%
      filter(abbreviation %in% all_abbreviations_used)

tada! Simple, useful.

Do you have ideas how to expand this idea? Perhaps you could scan the text of a document and extract abbreviations?

To leave a comment for the author, please follow the link and comment on their blog: Category R on Roel's R-tefacts.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.