updated R script