citations in .rmd documents!

For those of you who use knitr to include r code and output dynamically in your text files, you’ll be pleased to know (if you don’t already) that you can apply similar magic to your citations! Using the r package knitcitations, you can automatically generate citations in a .rmd document from the DOI.

If you’re not already familiar with knitr, it’s worth checking out. You can write up text files in markdown format (a quick and easy syntax that lets you apply formatting like headings, italics, etc. to plain text files), and then add r code right in with the text and just save it as a .rmd instead of .md file. You can open it in r’s script editor, run code from it, and R Studio even comes with a button you can click to automatically apply the formatting and make the markdown look like pretty HTML output. The best part is that since the analyses are literally built into the file, updating the output is easier than easy. If you decide to remove an outlier, for example, all you do is remove that outlier from the dataset specified at the beginning of your file, and all of your output, plots, results, etc. will automatically update. You’ll never have to copy-paste a figure again!

Working in plain text files (like .rmd or .md files, instead of more complex formats like .doc) also opens up the wonderful world of version control. You can back up all of your work to a repository in bitbucket or github and have forever access to a neat catalogue of all of your changes, as well as collaborate seamlessly with others, merge different versions, etc. Really powerful tools.

I use .rmd (or .md) files for pretty much everything now. I love the fact that I can build code right into my notes. It’s great for R Club and Bayes Club notes, obviously, since those both rely heavily on r code, but I also use it to write about my research, to incorporate r code into handouts for teaching stats, and in my own notes when I take classes or attend seminars. I can generate an example in r to match whatever example the speaker is talking about, and then include the complete analysis he/she describes in my notes, including plots and everything. It’s pretty baller.

Comments are closed.