edited R script