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. Ifx
is missing then an output file is created from each of the.Rmd
files in the current working directory, given bygetwd()
.A logical scalar, either
TRUE
orFALSE
. Ifpdf = FALSE
then no PDF files are created. Ifpdf = TRUE
then what happens depends on whetherword
orhtml
is used.word
: if the Operating System is"windows"
, that is,.Platform$OS.type == "windows"
and the `OfficeToPDF` software has been installed (seeinstall_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 thechrome_print
function from thepagedown
package. Google Chrome must be installed prior to use of this option. An error message likeError in servr::random_port(NULL) : Cannot find an available TCP port
means that therandom_port
function in theservr
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
tormd2word
orrmd2html
. Ifzip = TRUE
then zip archives are produced containing the files created.- ...
Further arguments to be passed to
rmd2word
(for the functionword
) orrmd2html
(for the functionhtml
). Explainzip
.
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)
} # }