Misc utility functions for R (personal use)