Miscellaneous functions for R