R code for saving