0

I'm working with the sendmailR package and trying to attach a data.frame to the mail. The data.frame is rather large so the best way to attach it would be a pdf, a .txt file distorts the table so that the content is rather unread able.

Is there a way of attaching a pdf, i tried plot.table but, I can't attach this plot.

Any ideas? Thank you very much!

DOK
  • 32,337
  • 7
  • 60
  • 92
rainer
  • 929
  • 2
  • 14
  • 25

1 Answers1

1

I disagree that the best way would be a pdf. It will end up much bigger than it needs to be. Instead use dump or dput to create an ASCII text representation and save that to a .txt file that you attach. The mime_part {sendmailR} is used to construct attachments. You could also use mime_part.data.frame and bypass constructing the dump()-ed or dput()-ted steps.

You can find a worked example here: http://www.inside-r.org/node/95009

## Not run:from <- sprintf("<sendmailR@%s>", Sys.info()[4])
to <- "<olafm@datensplitter.net>"
subject <- "Hello from R"
body <- list("It works!", mime_part(iris))
sendmail(from, to, subject, body,
         control=list(smtpServer="ASPMX.L.GOOGLE.COM"))
## End(Not run)

If you want to examine code that attaches a pdf file then look at mime_part.trellis {sendmailR} which send a pdf print-ed() from a trellis/lattice object.

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • 1
    thanks for you answer! I already tried that example and attached the file as .txt but the problem is that the table (or data.frame) has numerical as well as strings variables in it and the strings vary from row to row. I haven't found a way that the table looks good. Not all values are below each other. I haven't tried *dput*, maybe this works. Or do you have any ideas about the problem with the varying column widths? Thx – rainer Jan 20 '12 at 18:25
  • You said you wanted to attach a data.frame. I assumed that meant you wanted it to be used as a dataframe by its recipient. If what you really want is something that looks pretty (but isn't really a dataframe) then either `capture.output` or `sink`. – IRTFM Jan 20 '12 at 18:40