SweaveGetSourceName {RweaveExtra}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:

  1. an expression passed to R -e or Rscript;

  2. 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.

Value

Filename as a character string.

Author(s)

Vincent Goulet

Examples

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()



[Package RweaveExtra version 1.2-0 Index]