updated R code