updated initial R code