| SweaveGetSourceName {utils} | R Documentation |
File Processed by Sweave or Stangle
Description
Extract the name of the file currently processed by
Sweave or Stangle in a
non-interactive session.
Usage
SweaveGetSourceName()
Details
The function returns the name of the source file being processed by
Sweave or Stangle when the tool is invoked from the
command line through either:
an expression passed to
R -eorRscript -e;-
R CMD SweaveorR CMD Stangle.
In the first scenario, the filename must be the first, unnamed
argument to Sweave or Stangle.
This function cannot be used from an interactive R session.
Value
Filename as a character string.
Author(s)
Vincent Goulet
Examples
nmRnw <- "example-4.Rnw"
exfile <- system.file("Sweave", nmRnw, package = "utils")
file.show(exfile)
## Sweave the file in a separate process using 'R CMD Sweave'
tools::Rcmd(c("Sweave", "--encoding=UTF-8", shQuote(exfile)))
## View the LaTeX file, including the 'exfile' path
nmtex <- sub("Rnw$", "tex", nmRnw)
file.show(nmtex)
## Stangle was called from within Sweave in the file
nmR <- sub("Rnw$", "R", nmRnw) # default R output file name
file.show(nmR)
## Also supported but less convenient here: Sweave via 'Rscript -e'
Rscript <- file.path(R.home("bin"), "Rscript")
expr <- sprintf("Sweave('%s', encoding = 'UTF-8')", exfile)
system2(Rscript, c("-e", shQuote(expr)))
file.show(nmtex)
file.show(nmR)
## Not supported: SweaveGetSourceName() called from tools::R()
try(tools::R(Sweave, list(exfile, encoding = "UTF-8")))
## Do not use the function interactively
## Not run: SweaveGetSourceName()
## Cleanup
unlink(c(nmtex, nmR))
[Package utils version 4.6.1 Index]