full R script