Category Archives: Uncategorized

Twin Primes

Extremely accessible overview of the work of Yitang Zhang and the polymath project on prime gaps, with a neat trick variant of the usual probabilistic method I hadn’t seen before.

Terry Tao, Ph.D. Small and Large Gaps Between the Primes

Advertisements

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()))