The is also this
that is very helpful to send emails prepared programmatically:
If you look ate the example, you'll have the ability to create template body using placeholder like {name}
to be replace with the variable you have in R. You even can exectute R code in {Sys.Date()}
. From the README:
library(blastula)
email_object <-
compose_email(
body = "
## Hiya! This is an email message. Exciting Right?
Enjoy it. And this here image:

**Yeah!** I seriously hope that you enjoy this \\
message and the good vibes it will bring to you \\
and yours.
Peace out,
{sender}",
footer =
"Brought to you by Smile AG on {current_date_time}",
sender = "Mike")
{current_date_time}
and {img_link}
are from the workspace of the current R session
{sender}
is provided in the function
The README shows a lot of feature.
You can also reproduce the templating feature with a package like whisker and it is sufficient if you don't need the rmarkdown rendering. You can use whisker
with any type of text document. Basically, you will read character string into R, these string will have placeholder and whisker syntax for its feature, you'll generate multiple text from these by using whisker rendering then you could write back the text in a file the way you want from R.
For example, assuming the text template has already been loaded in R as a vector of strings here (one by line)
tab <- tibble::tribble(
~"Name", ~"Phone",
"Mal", "737-3648",
"Zoe", "555-8641"
)
text <- c("Hello {{name}}",
"Please show up at my place on Mon 4th July",
"Best",
"Tom")
# map through your name vector
purrr::map(tab$Name, ~ whisker::whisker.render(text, list(name = .x)))
#> [[1]]
#> [1] "Hello Mal\nPlease show up at my place on Mon 4th July\nBest\nTom"
#>
#> [[2]]
#> [1] "Hello Zoe\nPlease show up at my place on Mon 4th July\nBest\nTom"
Created on 2018-11-08 by the reprex package (v0.2.1)
You see that whisker.render
generate a string with the place holder filled. Check the README and documentation to see how powerful if can be (conditional template and stuff like that).
You have also some tools like glue
that could be helpful for rendering multiple text with R variable.
tab <- tibble::tribble(
~"Name", ~"Phone",
"Mal", "737-3648",
"Zoe", "555-8641"
)
vec <- glue::glue_data(tab,
"Hello {Name}
Please show up at my place on Mon 4th July
Best
Tom")
vec
#> Hello Mal
#>
#> Please show up at my place on Mon 4th July
#>
#> Best
#>
#> Tom
#> Hello Zoe
#>
#> Please show up at my place on Mon 4th July
#>
#> Best
#>
#> Tom
# A character vector of length 2
str(vec)
#> 'glue' chr [1:2] "Hello Mal\n\n Please show up at my place on Mon 4th July\n \n Best\n\nTom" ...