The dirr
package can be used to set up a data project with default folders. Additionally, utility functions to compress data files and batch load/save Rds are provided.
The dirr
package can be installed from GitHub using the devtools
package and the following commands:
# install.packages("devtools")
library(devtools)
install_github("bgulbis\dirr")
- Create a new project folder, in RStudio or other
- Load the
dirr
package - Run the
make_dirs
function
libryar(dirr)
make_dirs()
The following folders are created by make_dirs
:
- data/external - any external data, such as data which was manually collected
- data/final - final version of the data used for analysis
- data/raw - original, raw data sets
- data/tidy - tidy version of original data sets
- doc - manuscript and related documents
- explore - exploratory notebooks and figures
- figs - final figures for posters or manuscript
- ref - reference articles for the project
- report - notebook containing data analysis
- src - R script files used to tidy, transform, and aggregate data into the final data set
- Load the
dirr
package - Run the
gzip_files
function to compress all data files in thedata/raw
directory, or other specified directory
library(dirr)
gzip_files()
- Use the
pattern
argument to specify only certain files for zipping - Use
ungzip_files
to uncompress all data files
- Load the
dirr
package - Run the
save_rds
function to save all R objects in the Global Environment whose names match the regular expression passed to thepattern
argument. The directory where the files are saved is specified by thedata.dir
argument - Use
get_rds
to load all files in the specified directory.
library(dirr)
# save all objects that begin with "tidy"
save_rds(data.dir = "data/tidy", pattern = "^tidy")
# read all Rds files
get_rds(data.dir = "data/tidy")
- Currently, the
file.ext
argument should be left as default.