View source: R/SweaveGetSourceName.R
SweaveGetSourceName | R Documentation |
Extract the name of the file currently processed by
Sweave
or Stangle
in a
non-interactive session.
SweaveGetSourceName()
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 -e
or
Rscript
;
R CMD Sweave
or R 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.
Filename as a character string.
Vincent Goulet
testfile <- system.file("examples", "example-source.Rnw",
package = "RweaveExtra")
## Check the contents of the file
if (interactive()) file.show(testfile)
## Sweave the file in a separate process
expr <- paste0("Sweave('", testfile, "', ",
"encoding = 'utf-8')")
system2("R", c("-e", paste0("\"", expr, "\"")))
## View woven file
if (interactive()) file.show("example-source.tex")
## Stangle was called from within Sweave in the file
if (interactive()) file.show("example-source.R")
## Repeat using 'R CMD Sweave'
system2("R", c("CMD", "Sweave", testfile, "--encoding=utf-8"))
if (interactive()) file.show("example-source.tex")
if (interactive()) file.show("example-source.R")
## Do not use the function interactively
## Not run: SweaveGetSourceName()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.