Learn R Programming

RweaveExtra (version 1.2-0)

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

Arguments

Value

Filename as a character string.

Author

Vincent Goulet

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.

Examples

Run this code
testfile <- system.file("examples", "example-source.Rnw",
                        package = "RweaveExtra")
oldwd <- setwd(tempdir())
## 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
if (FALSE) SweaveGetSourceName()

if (!interactive()) unlink(c("example-source*", ".Rprofile"))
setwd(oldwd)

Run the code above in your browser using DataLab