Learn R Programming

blastula (version 0.2.1)

compose_email: Create the email message

Description

Create an email message. String interpolation is possible for the text comprising the email body, footer, and preheader text. This is done by using curly braces to enclose R code chunks. Variables can be specified in the function call (using named arguments with ...), and any variables not found in ... will be searched for in the global environment.

Usage

compose_email(body = NULL, footer = NULL, .preheader_text = NULL,
  .title = NULL, .envir = parent.frame(), ...)

Arguments

body

the main body of text for the email message. Markdown can be used here (along with string interpolation via curly braces and named arguments) to construct the main text.

footer

the footer text for the email message. As with the body, Markdown and string interpolation can be used here.

.preheader_text

text that appears before the subject in some email clients. This must be plaintext.

.title

the title of the email message. This is not the subject but the HTML title text which may appear in limited circumstances.

.envir

allows for setting the environment.

...

expression strings for string interpolation for the body, footer, and preheader_text string data.

Value

an email_message object, which can be used for previewing with the preview_email() function or for sending out actual emails with the send_email_out() function.

Examples

Run this code
# NOT RUN {
# Create a simple email message using
# Markdown formatting
email <-
  compose_email(
  body = "
  Hello!

  ## This a section heading

  We can use Markdown formatting \\
  to **embolden** text or to add \\
  *emphasis*. This is exciting, \\
  right?

  Cheers")

# The email message can always be
# previewed using `preview_email()`
preview_email(email = email)

# We can use string interpolation to
# add in R code or strings assigned
# to variables; variables can be
# obtained from the global workspace
# or from temporary variables in the
# function call
sender_name <- "Mike"

email <-
  compose_email(
  body = "
  Hello!

  I just wanted to let you \\
  know that the {thing} that \\
  asked me for is ready to \\
  pick up. So, come over and \\
  do that.

  Cheers,

  {sender_name}",
  thing = "report")
# }

Run the code above in your browser using DataLab