{emayili} R Markdown Parameters

I don’t frequently use parameters in R Markdown documents. 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:                         Wed, 31 Jul 2024 11:50:23 GMT
X-Mailer:                     {emayili}-0.7.18
MIME-Version:                 1.0
Subject:                      Default parameter value
Content-Type:                 text/html; 
                              charset=utf-8

<html>
<head>
<title>Message with Parameter</title>
</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>

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:                         Wed, 31 Jul 2024 11:50:23 GMT
X-Mailer:                     {emayili}-0.7.18
MIME-Version:                 1.0
Subject:                      Better parameter value
Content-Type:                 text/html; 
                              charset=utf-8

<html>
<head>
<title>Message with Parameter</title>
</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>

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