inst/examples/example_mail_merge.R

## ---- input-data --------------------------------------------------------

dat <-  data.frame(
  email      = c("friend@example.com", "foe@example.com"),
  first_name = c("friend", "foe"),
  thing      = c("something good", "something bad"),
  stringsAsFactors = FALSE
)

## ---- markdown-message --------------------------------------------------

msg <- '
---
subject: "**Hello, {first_name}**"
---

Hi, **{first_name}**

I am writing to tell you about **{thing}**.

{if (first_name == "friend") "Regards" else ""}


Me
'


## ---- mail-merge --------------------------------------------------------

dat %>% 
  mail_merge(msg)

if (interactive()) {
  dat %>%
    mail_merge(msg) %>%
    print()
}

## ---- display shiny gadget ----------------------------------------------

if (interactive()) {
  dat %>%
    mail_merge(msg) %>%
    preview_mailmerge()
}

Try the mailmerge package in your browser

Any scripts or data that you put into this service are public.

mailmerge documentation built on Aug. 15, 2022, 1:05 a.m.