Learn R Programming

rmake (version 1.2.1)

rRule: Rule for running R scripts

Description

This rule executes R scripts to create various file outputs.

Usage

rRule(
  target,
  script,
  depends = NULL,
  params = list(),
  task = "all",
  preBuild = NULL,
  postBuild = NULL
)

Value

Instance of S3 class rmake.rule

Arguments

target

Name of output files to be created

script

Name of the R script to be executed

depends

A vector of file names that the R script depends on, or NULL.

params

A list of R values that become available within the script in a params variable.

task

A character vector of parent task names. The mechanism of tasks allows grouping rules. Anything different from 'all' will cause the creation of a new task depending on the given rule. Executing make taskname will then force building this rule.

preBuild

A character vector of shell commands to be executed before building the target

postBuild

A character vector of shell commands to be executed after building the target

Author

Michal Burda

Details

In detail, this rule executes the following command in a separate R process: params <- params; source(script)

That is, the parameters given in the params argument are stored in the global variable and then the script is sourced. Note that the re-generation of the Makefile with any change to params will not cause the re-execution of the recipe unless other script dependencies change.

Issuing make clean from the shell causes removal of all files specified in the target parameter.

See Also

rule(), makefile(), markdownRule()

Examples

Run this code
r <- rRule(target='cleandata.csv',
           script='clean.R',
           depends=c('data1.csv', 'data2.csv'))

# generate the content of a makefile (as character vector)
makefile(list(r))

# generate to file
tmp <- tempdir()
makefile(list(r), file.path(tmp, "Makefile"))

Run the code above in your browser using DataLab