Configuring R Markdown
I really love markdown. The simplicity and clean documents that it can generate. However, lately I have come across RMarkdown. A beefier version of markdown that can do so much more. It can run code, generate plots, including languages other than R which is cool.
But really, I wanted to create a document that follows the style of Edward R. Tufte, and some awesome people have put in the time to make a package that can do exactly this!
First, have R installed, this can be found here.
Then, just because it is more user friendly, install RStudio, it’s a nice light weight IDE that sometimes comes in handy.
Then, install the RMarkdown package inside R. If you want to do this inside of RMarkdown (or R), then all you will need is the following:
install.packages("rmarkdown")
Now, RMarkdown actually makes use of a number of other tools in order to generate the document that you want. Put simply, your ‘.Rmd’ file that you create will be fed into knitr, which will run all of the R code that you have in the file, and it will create a standard markdown file, this has the code and the generated output from each of the code blocks that you may have used. Next, and you are going to have to have pandoc installed for this next part, the compilation process uses pandoc to process the markdown file. This supposedly will generate your file.
Part of the process, naturally uses TeX, which is why, I think, the process generates .tex files.
Some way along the process of generating this document, it got stuck, after it had generated the .tex file.
So, as I already have MiKTeX installed on my system, I ran it there. It apparently needed to install a number of packages to get this to work, and MiKTeX generated the file that I wanted.
So, hoping that this was the reason that R was complaining, I ran the original script again, and voila, it generated the document without an issue!!
Anyways, the following line allows you to generate the document from the command line:
Rscript --default-packages=rmarkdown,tufte GenerateDoc.r
Where ‘GenerateDoc.r’ has:
#!/usr/bin/env Rscript
library("rmarkdown")
library("tufte")
rmarkdown::render('ProtocolDocumentation.Rmd')
The ‘.Rmd’ file also needs to have the following in its header:
---
title: Switching Protocols
author: Tristan Kuisis
date: '`r paste("First created on Feb 24, 2020. Updated on", Sys.Date())`'
output:
tufte::tufte_handout: default
tufte::tufte_html: default
---
Kinda weird, lots of setup to run a single ‘.Rmd’ Anyways, it works now.