R code edited