Skip to contents

Functions to create PDF files containing R output and/or Microsoft Word or HTML files from which PDF files can be produced.

Usage

word(x, pdf = isTRUE(.Platform$OS.type == "windows"), zip = FALSE, ...)

html(x, pdf = TRUE, zip = FALSE, ...)

Arguments

x

A character vector containing the names (no extension) of the .Rmd files to convert if they are in the current working directory, or paths to the files, either absolute or relative to the current working directory, e.g., DIRECTORY/file1. The output files are created in the same directory as their respective .Rmd file. If x is missing then an output file is created from each of the .Rmd files in the current working directory, given by getwd().

pdf

A logical scalar, either TRUE or FALSE. If pdf = FALSE then no PDF files are created. If pdf = TRUE then what happens depends on whether word or html is used.

  • word: if the Operating System is "windows", that is, .Platform$OS.type == "windows" and the `OfficeToPDF` software has been installed (see install_otp) then a PDF file is created from each Word file. Otherwise, no PDF files are created.

  • html: each html file is printed to a PDF file using the chrome_print function from the pagedown package. Google Chrome must be installed prior to use of this option. An error message like Error in servr::random_port(NULL) : Cannot find an available TCP port means that the random_port function in the servr package could not find an internet connection that Chrome considers secure. Perhaps you are using a coffee shop's wifi.

zip

A logical scalar. The argument zip to rmd2word or rmd2html. If zip = TRUE then zip archives are produced containing the files created.

...

Further arguments to be passed to rmd2word (for the function word) or rmd2html (for the function html). Explain zip.

Value

In addition to creating the required files, a list containing information about the files created. See the Return section of rmd2word or rmd2html for details.

Details

The functions rmd2word (for word) or rmd2html (for html) from the accessr-package are used.

Note

The pandoc software version 1.14 or higher is required, that is, rmarkdown::pandoc_available("1.14") must return TRUE. pandoc should be installed automatically if you are using RStudio.

Examples


if (FALSE) { # \dontrun{
# We copy example.Rmd to the current working directory.
# Then we call word() and html().

eg <- system.file(package = "stat0002", "examples", "example.Rmd")
file.copy(eg, getwd(), overwrite = TRUE)

# These examples are not run when the package is tested because they will
# not work on all operating systems.

# Create a Word file only
word("example", pdf = FALSE)

# Create an HTML file only
html("example", pdf = FALSE)

# We repeat this passing pdf = TRUE to create PDF files.

# Create a Word file and a PDF file
word("example", pdf = TRUE)

# Create an HTML file and a PDF file
html("example", pdf = TRUE)
} # }