Create a Glossary in R Markdown
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
I was thinking about creating a glossary in bookdown and found out that there was already an issue about it. I like Yihui’s recommendation: use Pandoc’s definition lists. This was exactly what I had been doing, but I quickly found out that there was a major drawback – the definition lists won’t order alphabetically unless written in that way.
So I wrote an R function to reorder the definition lists written in R Markdown. Note that this functions only works for R Markdown files containing defintion lists exclusively. If the R Markdown files aren’t whole-definition-lists, the function will fail.
Usage
To order the definition lists alphabetically, simply put the Rmd file path in the function. To have a different output file, provide the output file path as the second argument.
sort_def_list("glossary.Rmd") # sort_def_list("glossary.Rmd", "reordered.Rmd")
The output in PDF looks like this (I used the multicol
package)1:
Source Code
Notes
To see the source R Markdown file, visit
glossary.rmd
. To see the output PDF, visitglossary.pdf
↩
Visit R-bloggers
Last updated: 2018-10-24
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.