Some useful R function