Start of the R script

Initial import statements and minor munging.