helper R code