Render either Plain Markdown or R Markdown directly into the body of an email.
If input
is a file then it will be interpreted as R Markdown it its
extension is either "Rmd"
or "Rmarkdown"
. Otherwise it will be
processed as Plain Markdown.
A message object.
The input Markdown file to be rendered or a character vector of Markdown text.
A list of named parameters that override custom parameters specified in the YAML front-matter.
Whether to clean up whitespace in rendered document.
Extra CSS files.
Whether to include rendered CSS from various sources
("rmd"
— native R Markdown CSS; "bootstrap"
— Bootstrap CSS).
Language of content. If FALSE
then will not include
language field. If TRUE
then will attempt to auto-detect language.
Otherwise will use the specified language.
Whether or not to interpolate into input using glue.
The opening delimiter.
The closing delimiter.
Environment used for glue
interpolation. Defaults to parent.frame()
.
A message object.
Plain Markdown is processed with commonmark::markdown_html()
.
R Markdown is processed with rmarkdown::render()
.
Regardless of what output
type is specified in the input file,
render()
will always use the "html_document"
output format.
Rending an R Markdown document can result in a lot of CSS. When all of the
CSS is included in the HTML <head>
and sent to GMail it can result in a
message which is not correctly displayed inline in the Gmail web client.
To get around this you can specify include_css = FALSE
. This will mean
that some styling will not be present in the resulting message, but that
the message content will be correctly rendered inline.
# Plain Markdown
markdown <- "[This](https://www.google.com) is a link."
filename <- "message.md"
# Render from Markdown in character vector.
msg <- envelope() %>% render(markdown)
# Create a file containing Markdown
cat(markdown, file = filename)
# Render from Markdown in file.
msg <- envelope() %>% render(filename)
# Cleanup.
file.remove(filename)
#> [1] TRUE
# R Markdown
filename <- "gh-doc.Rmd"
# Create an Rmd document from template.
rmarkdown::draft(
filename,
template = "github_document",
package = "rmarkdown",
edit = FALSE
)
# Check for suitable version of Pandoc (https://pandoc.org/).
#
# Need to have version 2.0 or greater to support required --quiet option.
#
pandoc <- rmarkdown::find_pandoc()
suitable_pandoc <- !is.null(pandoc$dir) && grepl("^2", pandoc$version)
# Render from Rmd file.
if (suitable_pandoc) {
msg <- envelope() %>%
render(filename, include_css = c("rmd", "bootstrap"))
}
# Cleanup.
file.remove(filename)
#> [1] TRUE