completed R script