Adding code from CRAN.