{emayili} R Markdown Parameters
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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, 20 Sep 2021 08:20:59 GMT
Subject: Default parameter value
X-Mailer: {emayili}-0.5.2
MIME-Version: 1.0
Content-Type: multipart/related; boundary="9554b959"
--9554b959
Content-Type: text/html; charset=utf-8
Content-Disposition: inline
<html>
<head></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>
--9554b959--
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, 20 Sep 2021 08:20:59 GMT
Subject: Better parameter value
X-Mailer: {emayili}-0.5.2
MIME-Version: 1.0
Content-Type: multipart/related; boundary="a099637d"
--a099637d
Content-Type: text/html; charset=utf-8
Content-Disposition: inline
<html>
<head></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>
--a099637d--
? 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.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.