Grading R Markdown Files

This semester I’m the TA for a course on statistical graphics. The homework is done in R and submissions are required to be R Markdown (.Rmd) files. This was done so that all of the code and output are neatly presented and if the .Rmd file compiles it’s a sign that the students’ R code runs.

However, this presented a unique challenge as I wound up with too many R Markdown files to comfortably compile.

My solution (which should be OS independent) is to create a new directory with just the .Rmd files in it:

Two .Rmd files to be compiled, both in a fresh directory.

I then run R (just type <R> into your terminal emulator). A quick list.files() verifies that we’re in the right working directory:

Running R and calling list.files() to verify that the .Rmd files we want to compile are in our current working directory.

Running R and calling list.files() to verify that the .Rmd files we want to compile are in our current working directory.

Now, we have a list of the files that we want to compile, and the function we want to apply to each of the files is knit2html() (or knit2pdf()). However, I’ve noticed that some weird dependency/global variable strangeness happens if you don’t purge the environment before compiling each document. Luckily, knit2html()/knit2pdf() has a built-in option to handle this. The code is:

sapply(list.files(), function(x) knit2html(x, envir=new.env()))

RStudio on Hi-DPI/Retina displays in Windows

If you are using a Hi-DPI display to view RStudio in Windows, you will notice that the RStudio window and text/elements are too tiny to work with. After searching for a solution online that didn’t involve me setting my monitor resolution to non-Retina levels, I stumbled upon the “zoom” setting under Tools>Global Options>Appearance.

I found 175% comfortable on my 13″ Retina MacBook Pro.