implement a function to write an R script