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/
Why Use 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.
Key Features
- Integration with Make: Uses the well-known Make tool for dependency management
- Easy Definitions: Define file dependencies using R syntax
- High Flexibility: Parameterized execution of R scripts and programmatically generated dependencies
- Pipeline Operator: Simple and short code thanks to the special
%>>%operator - Multiple Rule Types: Support for R scripts, R markdown files, and custom rules
- Extensibility: Easy to define custom rule types
- Parallel Execution: Leverage Make's parallel processing features
- Cross-platform: Support for Unix (Linux), MacOS, MS Windows, and Solaris
- RStudio Compatible: Works seamlessly with RStudio's build system
Installation
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")
Setup
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:
Finding R_HOME
To find the correct value for your system, run this in R:
R.home()
Setting 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.
Basic Usage
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:
- Let us assume that you have rmake package as well as the
maketool properly installed. - Create a new directory (or an R studio project) and copy your
dataset.csvinto it. - Load rmake and create skeleton files for rmake:
library(rmake) rmakeSkeleton('.')
Makefile.RandMakefilewill be created. - Create your file
preprocess.R,report.Rmdanddetails.Rmd. - Edit
Makefile.Ras follows:This will create three build rules: one for processinglibrary(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.Rand two for executingreport.Rmdanddetails.Rmdto generate the resulting PDF files. - Run
makeor build your project in R Studio (Build/Build all). This will automatically re-generateMakefileand executepreprocess.Rand the generation ofreport.Rmdanddetails.Rmdaccording to the changes made to the source files.