{emayili} R Markdown Parameters

I don’t frequently use parameters in R Markdown documents. So the initial implementation of render() in {emayili} did not cater for them. A small tweak makes it possible though.

You can install the update from GitHub as follows.

remotes::install_github("datawookie/emayili", ref = "v0.5.2")

Then load the package.

library(emayili)

# A couple of options to display message body.
#
options(
  envelope.details = TRUE,
  envelope.invisible = FALSE
)

Create an empty message object.

msg <- envelope()

Suppose you have the following simple R Markdown document, params.Rmd, which you want to render into the body of an email.

---
title: "Message with Parameter"
output: html_document
params:
  value: 13
---

The value is `r params$value`.

We’ll start by rendering it using the default parameter value.

msg %>%
  subject("Default parameter value") %>%
  render("params.Rmd", include_css = FALSE)
Date:                      Mon, 18 Oct 2021 07:31:45 GMT
X-Mailer:                  {emayili}-0.6.5
MIME-Version:              1.0
Subject:                   Default parameter value
Content-Type:              multipart/related; boundary="6786e9fe"

--6786e9fe
Content-Type:              text/html; charset=utf-8
Content-Disposition:       inline

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>
<body>
<div class="container-fluid main-container">
<div id="header">
<h1 class="title toc-ignore">Message with Parameter</h1>
</div>
<p>The value is 13.</p>
</div>
</body>
</html>

--6786e9fe--

As expected, the default value for the parameter comes through.

Now let’s test a different value.

msg %>%
  subject("Better parameter value") %>%
  render("params.Rmd", params = list(value = 42), include_css = FALSE)
Date:                      Mon, 18 Oct 2021 07:31:45 GMT
X-Mailer:                  {emayili}-0.6.5
MIME-Version:              1.0
Subject:                   Better parameter value
Content-Type:              multipart/related; boundary="b5f74cca"

--b5f74cca
Content-Type:              text/html; charset=utf-8
Content-Disposition:       inline

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>
<body>
<div class="container-fluid main-container">
<div id="header">
<h1 class="title toc-ignore">Message with Parameter</h1>
</div>
<p>The value is 42.</p>
</div>
</body>
</html>

--b5f74cca--

🚀 Success: the specified parameter value now appears. If you use parameters in your R Makrkdown documents, then you can be confident that these will now work in {emayili} too.


The {emayili} package is developed & supported by Fathom Data.