Skip to content
Prev 8051 / 398506 Next

putting output from print() into a string?

That's right, dump() doesn't do what I want: I should have made it 
clearer that what I would like to store in a string is the 
prettily-printed representation that gets displayed on the console 
when print() is called.  Yes, sink()-ing to a string would be nice. 
Or perhaps (more radically?) an optional argument as in print(mydata, 
return.the.string=TRUE) which requests the return of a string instead 
of returning the object mydata itself.
I somehow thought I'd be asked this!  I need to exchange information 
rapidly with a non-R user using write.socket(), and for that purpose 
the information has to be in the form of a character string.  I can 
of course format the string myself using formatC(), paste(), etc., 
but it turns out that the way that data frames get formatted by 
print.matrix() is just right for my purposes.  So, rather than 
duplicate some of the excellent work that went into print.matrix(), 
I'd like to use it!

Thanks anyway for your very helpful answer, Peter: at least I can 
stop looking now.

Regards -- David
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._