Search code examples
rsendmailquantmod

R - chartSeries using dev.copy to save from script not working


My script below works when run from the R console; but saves and emails a blank .jpeg file when run from an R script/batch file. Any help would be greatly appreciated.

I'm trying to email my chartSeries() after my R script runs.

chartSeries(test)
dev.copy(jpeg,'test.jpeg')
dev.off()

from <- "myemailaddress"
to <- "<myemailaddress>"
subject <- "test"
body <- list("test")                   
mailControl=list(smtpServer="192.168.0.51")
attachmentObject <- mime_part(x="test.jpeg",name="test.jpeg")
bodyWithAttachment <- list(body,attachmentObject)
sendmail(from=from,to=to,subject=subject,msg=bodyWithAttachment,control=mailControl)

Solution

  • Wrap your chartSeries call in plot:

    plot(chartSeries(test))