Move the scripting to R

Easier to assume R knowledge than shell knowlege.  More tools available,
increases chance that the boilerplate will be able to stay the same.