Makefile generator for R analytical projects
To install rmake, simply issue the following command within your R session:
install.packages("rmake")
Alternatively, you can install the latest development version from GitHub using the devtools package:
install.packages("devtools")
library(devtools)
devtools::install_github("beerda/rmake")
The package requires the R_HOME
environment variable to be properly set.
Suppose you have a file dataset.csv
. You want to pre-process it and store the results into dataset.rds
within the preprocess.R
R script. After that, dataset.rds
is then an input file for
report.Rmd
and details.Rmd
, which are R-Markdown scripts that generate report.pdf
and
details.pdf
. The whole project can be initialized with rmake as follows:
- Let us assume that you have rmake package as well as the
make
tool properly installed. - Create a new directory (or an R studio project) and copy your
dataset.csv
into it. - Load rmake and create skeleton files for rmake:
library(rmake) rmakeSkeleton('.')
Makefile.R
andMakefile
will be created. - Create your file
preprocess.R
,report.Rmd
anddetails.Rmd
. - Edit
Makefile.R
as follows:This will create three build rules: processing oflibrary(rmake) job <- c('dataset.csv' %>>% rRule('preprocess.R') %>>% 'dataset.rds' %>>% markdownRule('report.Rmd') %>>% 'report.pdf', 'dataset.rds' %>>% markdownRule('details.Rmd') %>>% 'details.pdf') ) makefile(job, 'Makefile')
preprocess.R
and execution ofreport.Rmd
anddetails.Rmd
in order to generate resulting PDF files. - Run
make
or build your project in R Studio (Build/Build all). This will automatically re-generateMakefile
and executepreprocess.R
and the generation ofreport.Rmd
anddetails.Rmd
accordingly to the changes made to source files.