I'm working with the 'pander' and 'sendmailr' packages to send a small data frame in the body of an email, rather than as an attachment. I'd like to send it from and to a gmail account.
I'm close, but the column headers won't align with the columns themselves in the email body the way they do in Rstudio for example- basically the column headers are too wide to line up with the data columns below them.
It seems the problem is the way the dashes and whitespaces are compressed in various email clients (I tried this in gmail, yahoo and hotmail through the web and through the email client that ships with OS X Mavericks). I was able to remedy the problem in my OS X email client by going to 'preferences' and checking the box labeled 'use fixed-width font for plain-text messages' but I'd like it to work on multiple devices, with multiple clients, etc for many of my coworkers so I'm wondering if there's a way that doesn't involve global email settings.
Here is the code to reproduce the problem:
library(sendmailR) # for emails from R
library(pander) # for table-formatting that does not require HTML
results <- head(iris)
pander(results) # widths look great so far...
a = pandoc.table.return(results)
strsplit(a, "\n") # widths still look great...
panderOptions('table.split.table', Inf) # show all columns on same line
msg_content <- mime_part(
pandoc.table.return(results, style = "multiline")
)
# I'm using my own gmail address for email_from and email_to
sendmail(from = email_from,
to = email_to,
subject = "test",
msg = msg_content
)
… and the email received has the problem described above.
Next you can see an image which illustrates the problem: