Miscellaneous R functions