[R] Sending a matrix in an email

Ira Fuchs irafuchs at gmail.com
Mon Nov 18 15:54:18 CET 2013


That's the ticket!  So many functions…so little time.  Thanks to everyone.
On Nov 18, 2013, at 9:47 AM, David Winsemius wrote:

> 
> On Nov 18, 2013, at 8:30 AM, Ira Fuchs wrote:
> 
>> Thanks for the suggestion. I just tried dput and it did not produce what sendmailR requires for the body parameter. Here is a simplified version of what I need to do:
>> 
>>> x=matrix(c(1,2,3),1,3)
>>> x
>>    [,1] [,2] [,3]
>> [1,]    1    2    3
>>> colnames(x)=c("a","b","c")
>>> x
>>    a b c
>> [1,] 1 2 3
>> 
>>> dput(x)
>> structure(c(1, 2, 3), .Dim = c(1L, 3L), .Dimnames = list(NULL,
>>   c("a", "b", "c")))
>> 
>> I want to send x in sendmailR(to,from,x) and have it look more or less like the output above. Simple, right?
> 
> After this at the console:
> 
> sink("myfile.txt")
> > x=matrix(c(1,2,3),1,3)
> > x
> > colnames(x)=c("a","b","c")
> > x
> > sink()
> 
> I get this in myfile.txt:
> 
>     [,1] [,2] [,3]
> [1,]    1    2    3
>     a b c
> [1,] 1 2 3
> 
> There is also a capture.output function.
> 
> -- 
> David
> 
>> 
>> 
>> On Nov 18, 2013, at 9:13 AM, Sarah Goslee wrote:
>> 
>>> What about dput()?
>>> 
>>> On Mon, Nov 18, 2013 at 8:35 AM, Ira Fuchs <irafuchs at gmail.com> wrote:
>>>> I have a matrix which has colnames and I would like to send this matrix using sendmailR. How can I convert this simple matrix to a format which can be used as the body variable in sendmailR? I see how I can create a file attachment using mime_part but I would like to send the matrix in the body of the email.
>>>> 
>>>> The matrix looks like:
>>>> 
>>>>    ABD  DEF  GHI  JKL MNO   TOT
>>>> [1,] 0.44 0.81 1.67 0.37 0.31 -1.18
>>>> 
>>>> 
>>>> All the conversions I have tried end up sending the matrix without the colnames.
>>>> 
>>>> Thanks.
>>>> 
>> 
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 
> David Winsemius, MD
> Alameda, CA, USA
> 



More information about the R-help mailing list