Checked in an R version of the code, to compare ours against