rpandersendmailr

sharing 2 data tables through sendmailR


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)

Solution

  • 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>