A few utility functions in R