Some useful R functions