Search code examples
rpandersendmailr

Not able to send the pander table intact in Gmail using sendmailR


Please find below my code that I am using to share my analysis (dataframe) with my friend in R. I am using sendmailR package and pander:

library(sendmailR)

from <- "<[email protected]>"
to <- "<[email protected]>"
subject <- "Important Report of the Day!!"
body <- "This is the result of the test:"                     
mailControl=list(smtpServer="ASPMX.L.GOOGLE.COM")
#-----------------------------------------------------
msg_content <- mime_part(paste('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body><pre>', paste(pander_return(pander(vvv, style="multiline")), collapse = '\n'), '</pre></body>
</html>'))

msg_content[["headers"]][["Content-Type"]] <- "text/html"

sendmail(from=from,to=to,subject=subject,msg=msg_content,control=mailControl)

Problem is that in the mail the table is broken into two parts (8 column table and 4 column table) PFB the sample picture

enter image description here

How do I change my code so that my table of 12 columns remain intact.

After adding this line

panderOptions('table.split.table', Inf)

This is the email that I am getting enter image description here


Solution

  • You have to increase or disable the default max width of the resulting markdown table via the split.tables argument of pandoc.table (that can be also used with the pander call, which will pass that argument to pandoc.table after all) or update the global options via panderOptions.

    Quick example on updating your pander call:

    paste(pander_return(pander(vvv, split.tables = Inf)), collapse = '\n')
    

    Or set that globally for all future pander calls:

    panderOptions('table.split.table', Inf)