SweaveAll: Apply Sweave to a collection of files.

Description Usage Arguments Details Value Author(s) Examples

View source: R/SweaveAll.R

Description

This function allows a master Sweave input file to specify other files in the project. All modified files will be run through Sweave. Following the run, several post-processing steps may be performed.

Usage

1
2
3
4
5
6
SweaveAll(SweaveFiles, make = 1, PostSweaveHook = NULL, 
          force = TRUE, verbose = FALSE, 
          weave = utils::Sweave, ...)
knitAll(RnwFiles, make = 1, PostKnitHook = NULL, 
          force = TRUE, verbose = FALSE, 
          weave = knitr::knit, ...)          

Arguments

SweaveFiles, RnwFiles

character vector naming the files to run through weave.

make

integer indicating which files to run weave on. See below.

PostSweaveHook, PostKnitHook

default hook to be called after each weave call. See below.

force

If TRUE, all files in SweaveFiles will be run, otherwise only those which are newer than the corresponding ‘.tex’ file.

verbose

Mainly for debugging: print progress messages.

weave

The function to be used for converting from source to ‘.tex’. It will be called as weave(filename, ...) for each file in SweaveFiles and other files identified as needing weaving.

...

Extra parameters to pass to weave.

Details

This function runs weave repeatedly. It starts by checking for a global variable .SweaveFiles, and augments the SweaveFiles argument with any unprocessed files in that list. It then runs weave on each file listed in SweaveFiles.

Before each run, it removes the global variables .PostSweaveHook, .SweaveFiles, and .TexRoot. The individual Sweave files may set these variables to control post- processing as described below.

Following each run, SweaveAll checks whether the code chunks created a variable .PostSweaveHook in the global environment. If present, it should be a function (or the name of a function; match.fun is used to do the lookup) taking a single argument. If not present, the PostSweaveHook (or PostKnitHook) argument will be used as a default. SweaveAll will pass the name of the ‘.tex’ output file to this function, which can do any required postprocessing. For example, we have used it to remove local pathnames from output strings.

SweaveAll then checks again for .SweaveFiles, which if present should be a character vector of filenames. These are collected, and after the Sweave runs specified by SweaveFiles, the make parameter controls which other files are run. The default value of 1 works as follows: any new files added via .SweaveFiles that were not already processed are checked. If they are newer than the corresponding ‘.tex’ file, or the ‘.tex’ file does not exist, they are processed. They may also return new filenames in the global .SweaveFiles variable and those will be processed as well.

Setting make = 2 forces all mentioned files to be processed. With make = 0, only the original vector of files passed to SweaveAll will be processed.

SweaveAll also checks for a global variable named .TexRoot. If present, it will be placed in the first position in the result vector. (If it was already in the vector, later copies will be removed.)

Value

The names of all files produced. The first element of Sweavefiles will produce the first element of the result if .TexRoot was not specified; other elements will depend on which files were processed.

Author(s)

Duncan Murdoch

Examples

1
2
3
4
5
6
7
8
## Not run: 
# Run Sweave on a main file, and obtain other files from there.
SweaveAll("main.Rnw")

# Run knitr on the same file.
SweaveAll("main.Rnw", weave = knitr::knit)

## End(Not run)

patchDVI documentation built on May 5, 2020, 3 p.m.