render | R Documentation |
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.
render(
msg,
input,
params = NULL,
squish = TRUE,
css_files = c(),
include_css = c("rmd", "bootstrap"),
language = FALSE,
interpolate = TRUE,
.open = "{{",
.close = "}}",
.envir = NULL
)
msg |
A message object. |
input |
The input Markdown file to be rendered or a character vector of Markdown text. |
params |
A list of named parameters that override custom parameters specified in the YAML front-matter. |
squish |
Whether to clean up whitespace in rendered document. |
css_files |
Extra CSS files. |
include_css |
Whether to include rendered CSS from various sources
( |
language |
Language of content. If |
interpolate |
Whether or not to interpolate into input using glue. |
.open |
The opening delimiter. |
.close |
The closing delimiter. |
.envir |
Environment used for |
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.
text
, html
# 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)
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.