rmd2pdf: Convert Rmd to PDF

Description Usage Arguments Details Value Author(s) Examples

View source: R/runme.R

Description

Convert an Rmd file to PDF by Sweaveing or knitting and then compiling.

Usage

1
2
3
4
5
6
7
8
9
rmd2pdf(
  fn = NULL,
  wd = NULL,
  ...,
  verbose = FALSE,
  purl = TRUE,
  tangle = purl,
  backup = TRUE
)

Arguments

fn

One or more filenames ending in "*.Rmd".

wd

A working directory in which the Rmd file exists. Leave as NULL if file is in current working directory,

...

Arguments that will be passed to rmarkdown::render and rmarkdown::pdf_document. Our defaults set a LaTeX template, toc = TRUE, and the pandoc_args includes use of the listings class. Users may override by specifying named arguments for render(): c("output_file", "output_dir", "output_options", "intermediates_dir", "knit_root_dir", "runtime", "clean", "params", "knit_meta", "envir", "run_pandoc", "quiet", "encoding"). Users may also specify named arguments for pdf_document: ("toc", "toc_depth", "number_sections", "fig_width", "fig_height", "fig_crop", "fig_caption", "dev", "df_print", "highlight", "template", "keep_tex", "latex_engine", "citation_package", "includes", "md_extensions", "pandoc_args", "extra_dependencies").

verbose

The opposite of render(quiet = TRUE). Shows compile commentary and pandoc command. Can be informative!

purl

Default TRUE

tangle

Default TRUE, synonym for purl

backup

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

Details

Running this will be the same as running the rmd2pdf.sh script within the directory.

Value

A vector of output file names

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
23
tdir <- tempdir()
fmt <- "rmd2pdf-guide"
dirout <- initWriteup(fmt, dir = file.path(tdir, fmt))
print(dirout)
list.files(dirout)

of1 <- try(rmd2pdf("skeleton.Rmd", wd = dirout))
if(inherits(of1, "try-error")){
    MESSG <- paste("Compiling the markdown file failed, perhaps",
                  "you should run with parameters verbose=TRUE",
                  "and keep_tex=TRUE")
    print(MESSG)
} else {
    ## Check the result file:
    MESSG <- paste("Check the directory", dirout, "for results.")
    print(MESSG)
    list.files(dirout)
    if(interactive() && file.exists(file.path(dirout, "skeleton.pdf"))) {
        browseURL(of1)
    }
}

unlink(dirout)

Example output

[1] "/work/tmp/tmp/RtmpknXU1X/rmd2pdf-guide"
[1] "instructions.Rmd" "R.bib"            "rmd2pdf.R"        "rmd2pdf.sh"      
[5] "skeleton.Rmd"     "theme"           


processing file: skeleton.Rmd

  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |......                                                                |   9%
  |                                                                            
  |.............                                                         |  18%
  |                                                                            
  |...................                                                   |  27%
  |                                                                            
  |.........................                                             |  36%
  |                                                                            
  |................................                                      |  45%
  |                                                                            
  |......................................                                |  55%
  |                                                                            
  |.............................................                         |  64%
  |                                                                            
  |...................................................                   |  73%
  |                                                                            
  |.........................................................             |  82%
  |                                                                            
  |................................................................      |  91%
  |                                                                            
  |......................................................................| 100%
output file: skeleton.R

Error : pandoc version 1.12.3 or higher is required and was not found (see the help page ?rmarkdown::pandoc_available).
[1] "Compiling the markdown file failed, perhaps you should run with parameters verbose=TRUE and keep_tex=TRUE"

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