From 12d0c36ff1fffe126c51b2e1ee22a786f19b7fd9 Mon Sep 17 00:00:00 2001 From: Andrie de Vries Date: Mon, 7 Mar 2022 15:51:25 +0000 Subject: [PATCH] Fix URLs --- README.Rmd | 2 +- README.md | 3 +- man/fragments/intro_example.html | 461 +++++++++++++++++++++++++++++++ 3 files changed, 464 insertions(+), 2 deletions(-) create mode 100644 man/fragments/intro_example.html diff --git a/README.Rmd b/README.Rmd index 9548aec..a52f714 100644 --- a/README.Rmd +++ b/README.Rmd @@ -19,7 +19,7 @@ knitr::opts_chunk$set( [![R-CMD-check](https://github.com/andrie/mailmerge/workflows/R-CMD-check/badge.svg)](https://github.com/andrie/mailmerge/actions) -[![Codecov test coverage](https://codecov.io/gh/andrie/mailmerge/branch/main/graph/badge.svg)](https://codecov.io/gh/andrie/mailmerge?branch=main) +[![Codecov test coverage](https://app.codecov.io/gh/andrie/mailmerge?branch=main)](https://app.codecov.io/gh/andrie/mailmerge?branch=main) [![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) diff --git a/README.md b/README.md index f055d88..de8e7ff 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![R-CMD-check](https://github.com/andrie/mailmerge/workflows/R-CMD-check/badge.svg)](https://github.com/andrie/mailmerge/actions) [![Codecov test -coverage](https://codecov.io/gh/andrie/mailmerge/branch/main/graph/badge.svg)](https://codecov.io/gh/andrie/mailmerge?branch=main) +coverage](https://app.codecov.io/gh/andrie/mailmerge?branch=main)](https://app.codecov.io/gh/andrie/mailmerge?branch=main) [![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) @@ -104,6 +104,7 @@ if (interactive()) { dat %>% mail_merge(msg) #> Sent preview to viewer + if (interactive()) { dat %>% mail_merge(msg) %>% diff --git a/man/fragments/intro_example.html b/man/fragments/intro_example.html new file mode 100644 index 0000000..1ed653b --- /dev/null +++ b/man/fragments/intro_example.html @@ -0,0 +1,461 @@ + + + + + + + + + + + + + +intro_example.knit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +

Construct a data frame with the content you want to merge into your +email:

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

Write the text of your email as a R markdown document. You can add +the subject line in the yaml header. Use {} braces inside +the email to refer to the data inside your data frame. Expressions +inside these braces will be encoded by the +glue::glue_data() function (See https://glue.tidyverse.org/).

+
msg <- '
+---
+subject: "**Hello, {first_name}**"
+---
+
+Hi, **{first_name}**
+
+I am writing to tell you about **{thing}**.
+
+{if (first_name == "friend") "Regards" else ""}
+
+
+Me
+'
+

Then you can use mail_merge() to embed the content of +your data frame into the email message. By default the email will be +shown in a preview window (in the RStudio viewer pane, if you use +RStudio).

+

To send the message, use send = "draft" (to save in your +gmail drafts folder) or send = "immediately" to send the +mail immediately.

+
library(mailmerge)
+library(gmailr, quietly = TRUE, warn.conflicts = FALSE)
+
+if (interactive()) {
+  # Note: you should always authenticate. The 'interactive()` condition only 
+  # prevents execution on the CRAN servers
+  gm_auth()
+}
+
dat %>% 
+  mail_merge(msg)
+
## Sent preview to viewer
+
if (interactive()) {
+  dat %>%
+    mail_merge(msg) %>%
+    print()
+}
+ + + + +
+ + + + + + + + + + + + + + +