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

# 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('RSP_refcard.tex.rsp')"

parses and evaluates RSP_refcard.tex.rsp and output RSP_refcard.pdf in the current directory. A CLI-friendly alternative to the above is:

Rscript -e R.rsp::rfile RSP_refcard.tex.rsp

Author

Henrik Bengtsson

See also

rstring() and rcat().

Examples

path <- system.file("exData", package="R.rsp")
pathname <- rfile("random.txt.rsp", path=path,
                  output=file.path(tempdir(), "random.txt"))
print(pathname)
#> RspFileProduct:
#> Pathname: /tmp/henrik/RtmpVRjGW6/random.txt
#> File size: 32 bytes
#> Content type: text/plain
#> Has processor: FALSE

lines <- readLines(pathname, warn=FALSE)
cat(lines, collapse="\n")
#> A random integer in [1,100]: 76 

file.remove(pathname)
#> [1] TRUE


# Passing arguments
path <- system.file("exData", package="R.rsp")
pathname <- rfile("random-args.txt.rsp", path=path, args=list(K=50),
                  output=file.path(tempdir(), "random-args.txt"))
print(pathname)
#> RspFileProduct:
#> Pathname: /tmp/henrik/RtmpVRjGW6/random-args.txt
#> File size: 31 bytes
#> Content type: text/plain
#> Has processor: FALSE

lines <- readLines(pathname, warn=FALSE)
cat(lines, collapse="\n")
#> A random integer in [1,50]: 37 

file.remove(pathname)
#> [1] TRUE


if (FALSE) {
# 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)
}
}