Some R functions