MPIDR Technical Report
R package and LaTex for MPIDR technical report: "Reading Human Fertility Database and Human Mortality Database data into R"
Here's a link to the paper: link
"Reading Human Fertility Database and Human Mortality Database data into R" by Timothy L. M. Riffe is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
HMDHFDplus
There is an R package inside this repository called HMDHFDplus.
This package contains some code migrated over from the DemogBerkeley package, also hosted on github, as well as some new code. The HMDHFDplus package only contains functions for reading data into R. The R code is also more oranized here. Currently there are functions for reading in HMD, JMD, CHMD, HFD, and HFC code, and there are plans to implement HLD code as well, once that database is done reorganizing.
Installation
The package is now on CRAN!: https://cran.r-project.org/web/packages/HMDHFDplus/
EDIT Aug 9, 2018 Now fixed for both HMD and HFD, HT @jasonhilton. CRAN now live. v1.9.1
EDIT Jan 3, 2017 The CRAN version has two major bugs due to changes in the websites of both HMD and HFD. These have been attended to here, but those changes have not yet made it to CRAN, so please just install from github as explained below EDIT Jan 3, 2017
This means you can install it using:
install.packages("HMDHFDplus")As long as you R version is relatively up to date. If not then either update your R or install the development version, hosted here, instructions below:
To download the development version of HMDHFDplus
- make sure you have the most recent version of R
- make sure you install the
httr,RCurl, andXMLpackages first, which are needed for handling logins and html parsing. These packages may require extra steps to install. See further (approximate) instructions depending on OS. - look at the OS-specific notes below to ensure the installation will work.
Either download the zip ball or tar ball, decompress and run R CMD INSTALL on it in the terminal command line. You can also look in the Builds folder of this repository for tar.gz files that you can try to install locally. The easiest way to install is to use the devtools package to install the development version:
# install.packages("devtools", dependencies = TRUE)
library(devtools)
install_github("timriffe/TR1/TR1/HMDHFDplus")Note: On *nix systems first run in the terminal:
sudo apt-get install libcurl
sudo apt-get install libxml2-dev
, to install the external libraries needed by RCurl and XML packages, respectively.
Note: Windows users need Rtools to install from github (or from source code) as shown above. Get the most recent version of R for Windows and download and install the version of Rtools that corresponds to it. You will also need the RCurl package, which requires an external program called cURL, which might require tenacity to get working on Windows. Do so cheaply using:
source("http://bioconductor.org/biocLite.R")
biocLite("RCurl")or similar. You may still need to install cURL first by by downloading the binary from here. You'll also need the XML R package, which you can install locally by downloading from here: http://cran.r-project.org/bin/windows/contrib/ (pick your R version and then search down the list). Then install after modifying:
install.packages("path/to/XML_version_x.zip", repos = NULL, type = "source")If you needed to figure out more details to get this to work, please report back so these instructions can be updated, as no test machine is available at the time of this writing.
Note: Mac users might be required to install the appropriate version of XTools from the Apple Developer site in order to install the development version of devtools. You may need to register as an Apple developer. An older version of XTools may also be required. Also, you'll need to install the RCurl package, which requires libcurl external. You'll also need XML, which you might be able to install using:
install.packages("XML", repos = "http://www.omegahat.org/R", type = "source")If that doesn't work, then figure it out and please report back, so these instructions can be updated. No test machine is available at the time of this writing.
To report a bug
Just go to the main repository page and click on the Issues
button on the right side. That's a convenient way to track bugs. Otherwise, just email the maintainer. Feature
requests can also be made to the maintainer. Motivated individuals are also free to offer assistance by collaborating via the git version control system and github.
As mentioned here and there above, if you learn of a better way to install dependencies for a particular OS, I'd appreciate the feedback. Unfortunately, the tricky external dependencies are necessary in order for downloading data that require registration (HMD, HFD). It seems the XML dependency could be eliminated if the HFD would publish a nice metadata csv like the HMD does...
