[R] is there a formatted output in R?

Thomas Lumley tlumley at u.washington.edu
Sat Mar 11 01:59:42 CET 2006


On Fri, 10 Mar 2006, Michael wrote:

> Oh yeah, it worked... I got it typed wrong in R console... that's why...
>
> but why is cat() preferred?

In this context, because it translates the \n to a newline and doesn't 
precede the output by [1].

So, if you are actually producing pretty output with sprintf() you 
probably want cat(), but if you have a vector of formatted text and you 
want to look at it (as data), print() would be better.

 	-thomas



>
> On 3/10/06, Thomas Lumley <tlumley at u.washington.edu> wrote:
>>
>> On Fri, 10 Mar 2006, Michael wrote:
>>
>>> something like "sprintf" in C?
>>>
>>> so I can do:
>>>
>>> print(sprintf("the correct result is %3.4f\n", myresult));
>>
>> Did you try this line of code? It actually works in R, although you would
>> probably prefer cat() instead of print().
>>
>>        -thomas
>>
>>>
>>> -------
>>>
>>> Also, I am desperately looking for a "clear console screen"  function in
>>> R...
>>>
>>> thanks a lot!
>>>
>>>       [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-help at stat.math.ethz.ch mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide!
>> http://www.R-project.org/posting-guide.html
>>>
>>
>> Thomas Lumley                   Assoc. Professor, Biostatistics
>> tlumley at u.washington.edu        University of Washington, Seattle
>>
>

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle




More information about the R-help mailing list