[R] Email out of R (code)

Uwe Ligges ligges at statistik.tu-dortmund.de
Sat Oct 29 17:37:44 CEST 2011


R has packages for almost everything, so there is "sendmailR" ....

Uwe Ligges


On 28.10.2011 20:04, MacQueen, Don wrote:
> The various suggestions seem kind of complex to me, at least on a
> unix-like system (including Mac OS X).
> This is what I do:
>
>    sink('tmp.txt')
>    cat('This is the body of the message\n')
>    sink()
>    system('cat tmp.txt | mail -s "A test email" macqueen1 at llnl.gov')
>
> One could probably avoid the temporary external text file using
> connections, but I haven't had that need.
>
>
> For attachments, the following approach works on at least some systems
> (RHEL for one):
>
>    pdf('temp.pdf')
>    ## create a plot
>    dev.off()
>
>    sink('tmp.txt')
>    ## print() and cat() commands
>    sink()
>
>    cmd<- '/bin/mailx -s "Subject line text"
>           -a temp.pdf -S replyto=macqueen1 at llnl.gov
>            recipient at some.host<  tmp.txt'
>    system(cmd)
>
>
> It's not hard, of course, to wrap such a thing up in a function with
> arguments for various elements such as the subject, the file names, the
> email address(es), and then construct the cmd using paste().
>
>



More information about the R-help mailing list