rnw2pdf: Convert an 'Rnw' document to PDF

View source: R/utils-conversion.R

rnw2pdfR Documentation

Convert an ‘Rnw’ document to PDF

Description

Call knit() to compile the ‘.Rnw’ input to ‘.tex’, and then tinytex::latexmk() to convert ‘.tex’ to ‘.pdf’.

Usage

rnw2pdf(
  input,
  output = with_ext(input, "pdf"),
  compiler = "xelatex",
  envir = parent.frame(),
  quiet = FALSE,
  clean = TRUE,
  error = FALSE,
  ...
)

Arguments

input

Path to the input file.

output

Path of the PDF output file. By default, it uses the same name as the input, but changes the file extension to ".pdf".

compiler, ...

The LaTeX engine and other arguments to be passed to tinytex::latexmk(). The default compiler is xelatex.

envir

Environment in which code chunks are to be evaluated, for example, parent.frame(), new.env(), or globalenv()).

quiet

Boolean; suppress the progress bar and messages?

clean

If TRUE, the intermediate files will be removed.

error

If FALSE, knitting stops when any error occurs.

Details

This function is similar to knit2pdf(), with the following differences:

  1. The default compiler is "xelatex" instead of "pdflatex".

  2. output uses the file extension ".pdf" instead of ".tex".

  3. Before knitting, it tries to remove the output file and will throw a clear error if the file cannot be removed.

  4. output could be under any dir, not necessarily the same directory as input.

  5. It cleans up intermediate files by default, including the ".tex" file.

  6. It stops knitting when any error occurs (by setting the chunk option error = FALSE).

Value

The output file path.


yihui/knitr documentation built on May 1, 2024, 5:37 p.m.