rmd2html: Convert an Rmd file into an HTML file

Description Usage Arguments Details Value Author(s) Examples

View source: R/runme.R

Description

This is a very simple wrapper around the rmarkdown::render function. It makes sure that the style sheet we want to use is applied to the data.

Usage

1
2
3
4
5
6
7
8
9
rmd2html(
  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 name of the Rmd file. If not specified, then the current working directory from R will be used.

...

Arguments that will be passed to rmarkdown::render and rmarkdown::html_document. We usually have customizations via parameters css and template, but many other parameters can be specified to change arguments for rmarkdown::render and rmarkdown::html_documents. These possible arguments for html_document: c("toc", "toc_depth", "toc_float", "number_sections", "section_divs", "fig_width", "fig_height", "fig_retina", "fig_caption", "dev", "df_print", "code_folding", "code_download", "smart", "self_contained", "theme", "highlight", "mathjax", "template", "extra_dependencies", "css", "includes", "keep_md", "lib_dir", "md_extensions", "pandoc_args"). These arguments intended for render() are allowed: c("output_file", "output_dir", "output_options", "intermediates_dir", "knit_root_dir", "runtime", "clean", "params", "knit_meta", "envir", "run_pandoc", "quiet", "encoding").

verbose

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

purl

Default TRUE, synonym for tangle. Set either one, or set both same, result is same.

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

result <- try(rmd2html("skeleton.Rmd", wd = dirout))
if(inherits(result, "try-error")){
    MESSG <- paste("Compiling the markdown file failed, perhaps",
                  "your version of pandoc is not found")
    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.html"))) {
        browseURL(file.path(dirout, "skeleton.html"))
    }
}
unlink(dirout)

stationery documentation built on Oct. 8, 2021, 5:07 p.m.