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.
- Create a directory for the R project (myproject)
- Create a subdirectory (myproject/data-raw)
- 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.
1 2 3 4 5 |
# mydata.R library(devtools) mydata = read.table("finalized_data.txt", header=T) devtools::use_data(mydata) |
This will create a file called mydata.rda
in the data
folder.
- in the R/ folder, create a data.R file and document the data set (below)
- update the DESCRIPTION file
- In Rstudio, run Build and Reload to see if the package builds correctly (control shift B)
- 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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#' @title dmdExonsHg19 #' #' @description List of DMD exons and their positions #' #' @details Precalculated list of DMD exons to skip #' in order to create an inframe transcript. #' #' @format A data frame of 4 columns and 79 rows #' \code{exon_stop}, \code{skip_to_render_inframe}, \code{starstop} #' \describe{ #' \item{exon_start}{DMD exon number at start of DMD deletion} #' \item{exon_stop}{DMD exon number at end of DMD deletion} #' \item{skip_to_render_inframe}{DMD exon to skip to render in-frame DMD transcript} #' \item{startstop}{comma sep list of exon start and exon end} #' } #' #' @section: Creator/maintainer #' My Name (my@email) "skips" |
To create the documentation
-
- Run
devtools::document()
or Build|Document in RStudio - Preview the documentation
?skips
- Repeat til satisfied
- Run
Another option is to use RStudio to create a new package.
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