Adding R code and functions