rnw2pdf: Convert (Sweave & compile) an Rnw or lyx file to PDF

Description Usage Arguments Value Author(s) Examples

View source: R/runme.R

Description

Documents saved with suffix ".lyx" or ".Rnw" will be converted. Note it is very important to specify the engine for the code chunks correctly, this can be either "Sweave" or "knitr".

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
rnw2pdf(
  fn = NULL,
  wd = NULL,
  ...,
  engine = "knitr",
  purl = TRUE,
  tangle = purl,
  backup = TRUE,
  clean = TRUE,
  quiet = TRUE,
  verbose = !quiet,
  envir = parent.frame(),
  encoding = getOption("encoding")
)

Arguments

fn

One or more file names, should end in either ".Rnw" or ".lyx"

wd

Directory in which the file to be converted exists. Leave NULL default if is in current working directory.

...

Other parameters, not used at the moment.

engine

"knitr" or "Sweave"

purl

Default TRUE. Synonym of tangle: extract R code chunks

tangle

Same as purl, both parameters have same result

backup

Default TRUE. Will create backup copies of pdf, R, Rnw files before replacing them. Uses kutils::file.backup

clean

Default TRUE. Remove intermediate LaTeX files when using texi2pdf

quiet

Default = TRUE. No output unless an error occurs. Antonym for verbose.

verbose

Default = !quiet. Antonym for quiet. Functions try to reduce amount of screen output. Knitr functions that use quiet flag will be set to !verbose.

envir

environment for evaluation, see knitr documents, defaults to parent.frame().

encoding

character encoding, defaults from user options

Value

names of pdf output files

Author(s)

Paul Johnson <pauljohn@ku.edu>

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
tdir <- tempdir()
fmt <- "rnw2pdf-guide-sweave"
dirout <- initWriteup(fmt, dir = file.path(tdir, fmt))
print(dirout)
list.files(dirout)
of1 <- try(rnw2pdf("skeleton.Rnw", engine = "Sweave", wd = dirout, backup = TRUE))
if(inherits(of1, "try-error")){
    MESSG <- paste("Compiling the markdown file failed, perhaps",
                   "there is an R or LaTeX error.", 
                   "Run again with parameters verbose=TRUE",
                   "and clean=FALSE")
    print(MESSG)
} else {
    ## Check the result file:
    MESSG <- paste("Check the directory", dirout, "for results.")
    print(MESSG)
    list.files(dirout)
    if(interactive() && file.exists(of1)) {
        browseURL(of1)
    }
}
unlink(dirout)

stationery documentation built on April 28, 2020, 5:13 p.m.