Packaging your data in R

Packaging your data in R

The goal of this is to make distribution of your data easy and consistent. The steps are not hard if you are using RStudio. The New Project wizard will do some of the work for you.

  1. Create a directory for the R project (myproject)
  2. Create a subdirectory (myproject/data-raw)
  3. In the subdir, do the data manipulation that needs to be done to get your data in shape (mydata.R)

Use devtools to create the myproject/data directory and create an RDA (data) file.

This will create a file called mydata.rda in the data folder.

  1. in the R/ folder, create a data.R file and document the data set (below)
  2. update the DESCRIPTION file
  3. In Rstudio, run Build and Reload to see if the package builds correctly (control shift B)
  4. You can also run Build Source to create a tar.gz file that you can install (R CMD INSTALL mydata.tar.gz)

Create Documentation

To document our data, use the R/data.R file we created. We use roxygen2. Text formatting reference sheet.

To create the documentation

    1. Run devtools::document() or Build|Document in RStudio
    2. Preview the documentation ?skips
    3. Repeat til satisfied

More details here.

 

References

http://tinyheero.github.io/jekyll/update/2015/07/26/making-your-first-R-package.html

https://support.rstudio.com/hc/en-us/articles/200486488-Developing-Packages-with-RStudio

Writing an R package from scratch