implemented the R script