[R] Is there an equivalent of "echo"

Steve Lianoglou mailinglist.honeypot at gmail.com
Mon Sep 14 23:13:32 CEST 2009


Hi,

On Sep 14, 2009, at 5:10 PM, Polwart Calum (County Durham and  
Darlington NHS Foundation Trust) wrote:

> Sorry I'm having one of those moments where I can't find the answer  
> but I bet its obvious...
>
> I'm outputting my results to a file using sink()
>
> Is there a command simillar to php's echo command that would allow  
> me to add some text to that file ie:

See ?cat

-steve

>
> dataFr$a = 1:10
> dataFr$b = 2*1:10
> sink ("filepath/filename.txt", split=T)
> #Show number of entries in vector a
> table (dataFr$a)
> #show number of entries in vector b
> table (dataFr$b)
> #show relationship between a and b
> table (dataFr$a , dataFr$b)
> sink()
>
> Gives me a text file like this:
> 1  2  3  4  5  6  7  8  9 10
> 1  1  1  1  1  1  1  1  1  1
>
> 2  4  6  8 10 12 14 16 18 20
> 1  1  1  1  1  1  1  1  1  1
>
>     2 4 6 8 10 12 14 16 18 20
>  1  1 0 0 0  0  0  0  0  0  0
>  2  0 1 0 0  0  0  0  0  0  0
>  3  0 0 1 0  0  0  0  0  0  0
>  4  0 0 0 1  0  0  0  0  0  0
>  5  0 0 0 0  1  0  0  0  0  0
>  6  0 0 0 0  0  1  0  0  0  0
>  7  0 0 0 0  0  0  1  0  0  0
>  8  0 0 0 0  0  0  0  1  0  0
>  9  0 0 0 0  0  0  0  0  1  0
>  10 0 0 0 0  0  0  0  0  0  1
>
> What I'd like is to be able to add some headers in the text file  
> maybe like this:
>
> sink ("filepath/filename.txt", split=T)
> echo "Number of entries in vector a"
> table (dataFr$a)
> echo "number of entries in vector b"
> table (dataFr$b)
> echo "relationship between a and b"
> table (dataFr$a , dataFr$b)
> sink()
>
> Giving an output like:
> Number of entries in vector a
> 1  2  3  4  5  6  7  8  9 10
> 1  1  1  1  1  1  1  1  1  1
> number of entries in vector b
> 2  4  6  8 10 12 14 16 18 20
> 1  1  1  1  1  1  1  1  1  1
> relationship between a and b
>     2 4 6 8 10 12 14 16 18 20
>  1  1 0 0 0  0  0  0  0  0  0
>  2  0 1 0 0  0  0  0  0  0  0
>  3  0 0 1 0  0  0  0  0  0  0
>  4  0 0 0 1  0  0  0  0  0  0
>  5  0 0 0 0  1  0  0  0  0  0
>  6  0 0 0 0  0  1  0  0  0  0
>  7  0 0 0 0  0  0  1  0  0  0
>  8  0 0 0 0  0  0  0  1  0  0
>  9  0 0 0 0  0  0  0  0  1  0
>  10 0 0 0 0  0  0  0  0  0  1
>
> Possible?  Without 200 lines of code?
>
> ********************************************************************************************************************
>
> This message may contain confidential information. If yo...{{dropped: 
> 21}}
>
> ______________________________________________
> 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.

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
   |  Memorial Sloan-Kettering Cancer Center
   |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact




More information about the R-help mailing list