Miscelaneous R functions