{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:                        Sun, 09 Jan 2022 05:27:26 GMT
X-Mailer:                    {emayili}-0.7.1
MIME-Version:                1.0
Subject:                     Default parameter value
Content-Type:                multipart/related;
                              boundary="f3be0770"

--f3be0770
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>

--f3be0770--

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:                        Sun, 09 Jan 2022 05:27:26 GMT
X-Mailer:                    {emayili}-0.7.1
MIME-Version:                1.0
Subject:                     Better parameter value
Content-Type:                multipart/related;
                              boundary="e8e2c9ba"

--e8e2c9ba
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>

--e8e2c9ba--

🚀 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](https://www.fathomdata.dev).