3

I am using below code to share the data frame "my_data1" with my friend and the code is working fine. But I have another data frame "my_data2" that I want to share. Please suggest where and how should I add the second table in my code

library(sendmailR)
library(pander)
from <- "<me@gmail.com>"
to <- "<friend@gmail.com>"
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(my_data1, style="multiline", caption = "Net Bookings")), collapse = '\n'), '</pre></body>
</html>'))

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

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

1 Answers1

3

Adding <p><pre>', paste(pander_return(pander(my_data2, style="multiline", caption = "New Caption")), collapse = '\n'), '</pre> between </pre> and </body> should give you the desired result.

When you want to insert some text between the two tables, you can do:

<p>the text you want to insert between the tables</p>
<pre>', paste(pander_return(pander(my_data2, style="multiline", caption = "New Caption")), collapse = '\n'), '</pre>
Jaap
  • 81,064
  • 34
  • 182
  • 193
  • Thanks a lot !! Can you also help me in adding a html attachment in the same code. Really appreciate your help – Ravinder Kumar Mar 17 '16 at 11:22
  • @RavinderKumar I have no experience with that, but maybe [this Q&A](http://stackoverflow.com/questions/2885660/how-to-send-email-with-attachment-from-r-in-windows) or [this Q&A](http://stackoverflow.com/questions/3572607/sendmailr-part2-sending-files-as-mail-attachments) can help. – Jaap Mar 17 '16 at 11:43