[R] Is there an equivalent of "echo"

Polwart Calum (County Durham and Darlington NHS Foundation Trust) calum.polwart at nhs.net
Mon Sep 14 23:10:57 CEST 2009


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:

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




More information about the R-help mailing list