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