I have developed a report that makes heavy use of the features in RMarkdown v2, especially the feature to add css classes and id's to html documents in order to have greater control over the output using style sheets. I wish to send these reports in the body of an email. I have been trying to do this using send.mail (mailR). According to their gitgub readme file (https://github.com/rpremraj/mailR/blob/master/README.md)
mailR does not currently support resolving inline images encoded using the data URI scheme. Use the workaround below instead:
First off, create the HTML file from the R terminal (the important thing here is that options does not include "base64_images" --- see ?markdown::markdownHTMLOptions):
library(knitr)
knit2html("my_report.Rmd", options = "")
Now you can send the resulting HTML file via mailR...
The problem is the knit2html seems to still use RMarkdown v1, which doesn't support the syntax for adding css classes and id's to documents. Is there any other workaround, for instance using rmarkdown::render and somehow passing through the options parameter? Or is there a timeline for knitr to use RMarkdown v2?
This can reproduced as follows:
ExampleStyles.css
.GreenItalic {
font-style: italic;
color: green;
}
Example.Rmd
---
output: html_document
css: ExampleStyles.css
---
# Heading { .GreenItalic }
When knitted (rendered) using RStudio, the output is as expected. "Heading" is in italics and green.
To send it by email the following code can be used:
library(mailR)
library(knitr)
ReportName <- "Example"
knit2html(paste0(ReportName, ".Rmd"), options = "", styles = "ExampleStyles.css")
send.mail(from = "RTestingTesting@gmail.com",
to = "RTestingTesting@gmail.com",
subject = "Subject",
html = TRUE,
inline = TRUE,
body = paste0(ReportName, ".html"),
smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "RTestingTesting", passwd = "Password", ssl = TRUE),
authenticate = TRUE,
send = TRUE)
However in this case the output is "Heading { .GreenItalic}" in black and non-italic. As far as I'm aware this is because knitr is using RMarkdown v1.