Learn R Programming

R.rsp (version 0.43.0)

rfile: Evaluates and postprocesses an RSP document and outputs the final RSP document file

Description

Evaluates and postprocesses an RSP document and outputs the final RSP document file.

Usage

# S3 method for default
rfile(file, path=NULL, output=NULL, workdir=NULL, type=NA, envir=parent.frame(),
  args="*", postprocess=TRUE, ..., verbose=FALSE)

Arguments

file, path

Specifies the RSP file to processed, which can be a file, a URL or a connection. If a file, the path is prepended to the file, iff given.

output

A character string or a connection specifying where output should be directed. The default is a file with a filename where the file extension (typically ".rsp") has been dropped from file in the directory given by the workdir argument.

workdir

The working directory to use after parsing and preprocessing, but while evaluating and postprocessing the RSP document. If argument output specifies an absolute pathname, then the directory of output is used, otherwise the current directory is used.

type

The default content type of the RSP document. By default, it is inferred from the output filename extension, iff possible.

envir

The environment in which the RSP document is preprocessed and evaluated.

args

A named list of arguments assigned to the environment in which the RSP string is parsed and evaluated. See cmdArgs.

postprocess

If TRUE, and a postprocessing method exists for the generated RSP product, it is postprocessed as well.

...

Additional arguments passed to the RSP engine.

verbose

See Verbose.

Value

Returns an RspProduct. If argument output specifies a file, then this is an RspFileProduct.

Processing RSP files from the command line

Using Rscript and rfile(), it is possible to process an RSP file from the command line. For example,

Rscript -e "R.rsp::rfile(file='RSP_refcard.tex.rsp', path=system.file('doc', package='R.rsp'))"

parses and evaluates RSP_refcard.tex.rsp and output RSP_refcard.pdf in the current directory.

See Also

rstring() and rcat().

Examples

Run this code
# NOT RUN {
path <- system.file("exData", package="R.rsp")
pathname <- rfile("random.txt.rsp", path=path)
print(pathname)

lines <- readLines(pathname, warn=FALSE)
cat(lines, collapse="\n")


# Passing arguments
path <- system.file("exData", package="R.rsp")
pathname <- rfile("random-args.txt.rsp", path=path, args=list(K=50))
print(pathname)

lines <- readLines(pathname, warn=FALSE)
cat(lines, collapse="\n")


# }
# NOT RUN {
# Compile and display the main vignette (requires LaTeX)
if (isCapableOf(R.rsp, "latex")) {
  path <- system.file("doc", package="R.rsp")
  pdf <- rfile("Dynamic_document_creation_using_RSP.tex.rsp", path=path)
  cat("Created document: ", pdf, "\n", sep="")
  if (interactive()) browseURL(pdf)
}
# }

Run the code above in your browser using DataLab