makefile {rmake} | R Documentation |
Generate Makefile from given list of rules (job
).
Description
In the (GNU) make
jargon, rule is a sequence of commands to build a result. In this package, rule
should be understood similarly: It is a command or a sequence of command that optionally produces some
files and depends on some other files (such as data files, scripts) or other rules. Moreover, a rule
contain a command for cleanup, i.e. for removal of generated files.
Usage
makefile(job = list(), fileName = NULL, makeScript = "Makefile.R",
vars = NULL, all = TRUE, tasks = TRUE, clean = TRUE,
makefile = TRUE)
Arguments
job |
A list of rules (i.e. of instances of the S3 class |
fileName |
A file to write to. If |
makeScript |
A name of the file that calls this function (in order to generate
the |
vars |
A named character vector of shell variables that will be declared in the resulting Makefile
(additionally to |
all |
|
tasks |
|
clean |
|
makefile |
|
Details
The makefile()
function takes a list of rules (see rule()
) and generates a Makefile
from them.
Additionally, all
and clean
rules are optionally generated too, which can be executed from shell
by issuing make all
or make clean
command, respectively, in order to build everything or erase all
generated files.
If there is a need to group some rules into a group, it can be done either via dependencies or by using
the task
mechanism. Each rule may get assigned one or more tasks (see task
in rule()
). Each
task is then created as a standalone rule depending on assigned rules. That way, executing make task_name
will build all rules with assigned task task_name
. By default, all rules are assigned to task all
,
which allows make all
to build everything.
Value
If fileName
is NULL
, the function returns a character vector with the contents of the
Makefile. Instead, the content is written to the given fileName
.
Author(s)
Michal Burda
See Also
Examples
# create some jobs
job <- list(
rRule('dataset.rds', 'preprocess.R', 'dataset.csv'),
markdownRule('report.pdf', 'report.Rmd', 'dataset.rds'),
markdownRule('details.pdf', 'details.Rmd', 'dataset.rds'))
# generate Makefile (output as a character vector)
makefile(job)
# generate to file
tmp <- tempdir()
makefile(job, file.path(tmp, "Makefile"))