Miscellaneous R code