Combines markdown files, HTML strings, and kable/kableExtra table objects into a single HTML email body. Use this when you need R-generated tables or other dynamic content mixed with prose.
Arguments
- ...
Parts to compose, in order. Each can be:
- Markdown file path
A
.mdfile path. The header above---is stripped (if present) and the body is converted to HTML.- HTML string
A character string of raw HTML, passed through as-is.
- kable/kableExtra object
Output from
knitr::kable()or kableExtra functions. Converted to character automatically.
- sig
Logical. Append signature? Default
TRUE.- sig_path
Path to a custom signature HTML file. Default
NULL.
Value
A character string of HTML ready for the html argument of
mc_send().
Details
For tables that look good in email:
Use
knitr::kable()for clean, simple tablesUse
kableExtra::row_spec()andkableExtra::column_spec()for inline styling (colors, bold, backgrounds)Avoid
bootstrap_optionslike"striped"— the CSS classes are stripped by GmailWrap large tables in
mc_scroll()for horizontal/vertical scrolling
mc_compose() automatically adds border and padding inline styles
to all <table>, <th>, and <td> elements for Gmail compatibility.
Examples
if (FALSE) { # \dontrun{
# Prose + table + more prose
df <- data.frame(Site = c("Nechako", "Mackenzie"), Plugs = c(4000, 3000))
body <- mc_compose(
"communications/intro.md",
knitr::kable(df, format = "html"),
"communications/closing.md"
)
mc_send(html = body, to = "someone@example.com", subject = "Update")
# Inline markdown (no file needed)
body <- mc_compose(
"<p>Hi Brandon,</p>",
knitr::kable(df, format = "html"),
"<p>Let me know if this looks right.</p>"
)
} # }
