revise the R code