rmake is an R package that creates and maintains a build process for complex analytic tasks. The package allows easy generation of a Makefile for the (GNU) 'make' tool, which drives the build process by executing build commands (in parallel) to update results according to given dependencies on changed data or updated source files.
Documentation: https://beerda.github.io/rmake/
R allows the development of repeatable statistical analyses, but when analyses grow in complexity, manual re-execution on any change may become tedious and error-prone. Make is a widely accepted tool for managing the generation of resulting files from source data and script files. rmake makes it easy to generate Makefiles for R analytical projects.
%>>% operatorTo 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. This variable indicates the directory where R is installed.
When running from within R or RStudio, this is automatically set and no action is needed.
When running make from the command line, you may need to set it manually:
To find the correct value for your system, run this in R:
R.home()
On Linux/macOS:
export R_HOME=/usr/lib/R # Use the path from R.home()
On Windows (Command Prompt):
set R_HOME=C:\Program Files\R\R-4.3.0 # Use the path from R.home()
On Windows (PowerShell):
$env:R_HOME = "C:\Program Files\R\R-4.3.0" # Use the path from R.home()
For permanent setup, add these to your shell configuration file (.bashrc, .zshrc, etc. on Unix-like systems).
For more information on R environment variables, see the official R documentation.
Suppose you have a file dataset.csv. You want to pre-process it and store the results into dataset.rds
using 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:
make tool properly installed.dataset.csv into it.library(rmake)
rmakeSkeleton('.')
Makefile.R and Makefile will be created.preprocess.R, report.Rmd and details.Rmd.Makefile.R as follows:
library(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')
This will create three build rules: one for processing preprocess.R and two for executing report.Rmd and details.Rmd
to generate the resulting PDF files.make or build your project in R Studio (Build/Build all). This will automatically re-generate Makefile
and execute preprocess.R and the generation of report.Rmd and details.Rmd according to the changes
made to the source files.