first version of the R code