Some handy R functions