write the new R code