I am relatively new to R programming and have undertaken a little side project to introduce myself to the world of R. What I would like to do is help one of my colleagues automate a manual email process that he does each week.
The email consists of a chart created in excel, DOW index prices, our company's stock prices, and some commentary that he manually updates each week.
I have figured out how to use the RDCOMClient package to send emails but what I would like to do is integrate into the body of the email (in HTML format if possible) the charts and stock prices that he also pulls. I am hoping to automate all of this so all he has to do is update commentary and run the script.
The key limiting factor here is the target audience, this will be going out to executives who really do not like having to open email attachments. They want to open an email on their phone, get the relevant information, and move on.
This is what my program looks like so far:
library(RDCOMClient)
OutApp <- COMCreate("Outlook.Application")
outMail = OutApp$CreateItem(0)
outMail[["To"]] = "test@test.com"
outMail[["subject"]] = "R Test"
outMail[["body"]] = "Hello"
outMail$Send()
Sure, first you save your image. Then use HTMLbody to insert the image using HTML code as follows:
library(htmlTable)
png("pictest.png")
plot(iris$Sepal.Length)
dev.off()
StockPrice <- "25.25"
MyHTML <- paste0("<html><p>This is a picture.</p>
<img src='C:/Users/iwes/Desktop/RWorkingFolder/pictest.png' >
<p> Our StockPrices is: $", StockPrice,
"<p>here is a table:</p>",
htmlTable(head(iris,5)))
library(RDCOMClient)
OutApp <- COMCreate("Outlook.Application")
outMail = OutApp$CreateItem(0)
outMail[["To"]] = "test@test.com"
outMail[["subject"]] = "R Test"
outMail[["HTMLbody"]] = MyHTML
outMail$Send()