Here is the R script