knitrRule: Rule for building text documents using the knitr package

View source: R/knitrRule.R

knitrRuleR Documentation

Rule for building text documents using the knitr package

Description

This rule executes knitr to create a text file, as described in knitr::knit().

Usage

knitrRule(target, script, depends = NULL, params = list(), task = "all")

Arguments

target

Name of the output file to be created

script

Name of the RNW file to be rendered

depends

A vector of file names that the markdown 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.

Details

This rule executes the following command in a separate R process: ⁠library(knitr); params <- params; knitr::knit(script, output=target)⁠

That is, the parameters given in the params argument are stored in the global variable and then the script is processed with knitr. 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.

Value

Instance of S3 class rmake.rule

Author(s)

Michal Burda

See Also

markdownRule(), rule(), makefile(), rRule()

Examples

r <- knitrRule(target='report.tex',
               script='report.Rnw',
               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"))

rmake documentation built on Nov. 12, 2025, 9:06 a.m.