This vignette describes the various types of build rules available in
rmake for defining how targets are built from their
dependencies.
For information on project management (initialization, running builds, cleaning), see the rmake Project Management vignette. For advanced features like tasks and templates, see the Tasks and Templates vignette.
All rule functions have the following common parameters:
target - Character vector of files to createdepends - Character vector of prerequisite files
(optional)task - Task name(s) for grouping (default: “all”)params - Parameters to pass to scripts (optional for
some rules)Each rule executes in a separate R process (no shared state).
Note: The task parameter is covered in detail in the Tasks and Templates vignette, and
the params parameter is explained in the parameterized
execution section of that vignette.
Executes an R script using Rscript. The rule is
triggered when any dependency or the script itself changes.
Parameters:
target - Name of the output file to be createdscript - Name of the R script to executedepends - Vector of file names that the script depends
on, or NULLparams - List of R values that become available within
the script in a params variabletask - Character vector of parent task namesExample:
Renders a document from R Markdown using
rmarkdown::render().
Parameters:
target - Name of the output file to be createdscript - Name of the R Markdown file to renderdepends - Vector of file names that the markdown script
depends on, or NULLformat - Output format specification (see below)params - List of R values available within the script
in a params variabletask - Character vector of parent task namesFormat Options:
"all" - All formats defined in the Rmd file"html_document" - HTML web page"pdf_document" - PDF document"word_document" - Microsoft Word"odt_document" - OpenDocument Text"rtf_document" - Rich Text Format"md_document" - MarkdownExample:
Executes knitr to create a text file using
knitr::knit(). This is useful for processing Sweave-style
documents (.Rnw files).
Parameters:
target - Name of the output file to be createdscript - Name of the Rnw file to be rendereddepends - Vector of file names that the knitr script
depends on, or NULLparams - List of R values available within the script
in a params variabletask - Character vector of parent task namesExample:
Copies a file from one location to another. The rule executes
$(CP) depends[1] target.
Parameters:
target - Target file name to copy the file todepends - Name of the file to copy from (only the first
element is used)task - Character vector of parent task namesExample:
Defines a dependency between targets without providing any execution script. This is useful when you want to specify that a target depends on another target but don’t need to execute any command to build it.
Parameters:
target - Target file name that depends on
dependsdepends - Character vector of prerequisite file
namestask - Character vector of parent task namesExample:
Runs the make process in a subdirectory. The subdirectory is assumed
to contain its own Makefile. This rule executes
make <targetTask> in the specified subdirectory.
Parameters:
target - Name of the subdirectorydepends - Must be NULLtask - Character vector of parent task namestargetTask - What task to execute in the subdirectory
(default: “all”)Example:
Forces manual action within the build process. Shows a custom error message instructing the user to perform a task manually. This is useful when transformation requires manual intervention.
Parameters:
target - Name of the file to be created manuallymessage - Custom message to display to the userdepends - Vector of prerequisite file names, or
NULLtask - Character vector of parent task namesExample:
Create custom rules using the general rule()
function:
Arguments:
target - Target file namesdepends - Prerequisite file namesbuild - Shell commands to build targetsclean - Shell commands to clean targetstask - Task assignmentphony - Whether target is a non-file target
(TRUE/FALSE)Predefined Make Variables:
$(R) - Path to Rscript binary$(RM) - File deletion command$(CP) - File copy commandExample with NodeJS:
r <- rule(target = "test.json",
depends = "test.js",
build = "node test.js",
clean = "$(RM) test.json")Define custom Make variables:
defaultVars["JS"] <- "/usr/bin/node"
job <- list(rule(target = "test.json",
depends = "test.js",
build = "$(JS) test.js",
clean = "$(RM) test.json"))The inShell() function converts R expressions to shell
commands:
inShell({ result <- 1 + 1; saveRDS(result, "result.rds") })
#> [1] "$(R) - <<'EOFrmake'" "{"
#> [3] " result <- 1 + 1" " saveRDS(result, \"result.rds\")"
#> [5] "}" "EOFrmake"Example rule using inShell():
rule(target = "result.rds",
build = inShell({ result <- 1 + 1; saveRDS(result, "result.rds") }),
clean = "$(RM) result.rds")Note: Overuse of inShell() is not
recommended. Prefer separate script files so Make can detect
changes.
rmake provides a comprehensive set of rule types:
For more information on related topics, see these vignettes: