Various R code