[R] xtable - print - suppress output

Don MacQueen macq at llnl.gov
Tue Sep 22 00:52:20 CEST 2009


I think there is a conceptual issue here.

The xtable() function does not actually create html. What it does is 
add some attributes to the dataframe that is given to it. Here's an 
example:

>  tmp <- data.frame( a =1:3, b= c('a','b','c') )
>  foo <- xtable(tmp)

>  class(foo)
[1] "xtable"     "data.frame"
>  unclass(foo)
$a
[1] 1 2 3

$b
[1] a b c
Levels: a b c

attr(,"row.names")
[1] 1 2 3
attr(,"align")
[1] "r" "r" "l"
attr(,"digits")
[1] 0 2 2
attr(,"display")
[1] "s" "d" "s"

The output of class(foo) tells us that foo is still a dataframe. It 
has two columns, a and b, just like tmp did. What it also has are 
some additional attributes, in this case some alignment information, 
some "digits" information, and some "display" information. And that 
is *all* that xtable() did.

The real work is done by the function print.xtable(). This takes the 
dataframe and its additional attributes and prints it using either 
html or LaTeX syntax, depending on the 'type' argument. This is why 
xtable() has relatively few optional arguments, but print.xtable() 
has many.  xtable() does not create html. print.xtable() creates html.

In other words, there is no such thing as saving the html table into 
a variable. It just doesn't work that way. All that is possible is to 
write it (print it) to either the screen or a file.

Which leads back to the question that one of the other responses 
asked ... what is the reason for saving it to an R object? What do 
you hope to accomplish by doing that, that you can't accomplish using 
print() ?

Hope this helps

-Don

p.s.
Besides xtable, other packages that help write html include Hmisc 
(already mentioned), hwriter, HTMLUtils, and R2HTML. Maybe one of 
them does things enough differently to do whatever it is you're 
looking for.

At 12:13 AM +0200 9/22/09, Martin Batholdy wrote:
>Am 21.09.2009 um 23:59 schrieb Rolf Turner:
>
>>
>>On 22/09/2009, at 9:52 AM, Martin Batholdy wrote:
>>
>>>hi,
>>>
>>>
>>>
>>>I use xtable to convert data.frames to html tables.
>>>But when I use the print-command I always get the whole output printed
>>>even if I just want to save the html table into a variable;
>>>
>>>table <- print(xtable(CERAT), type="html")
>>>
>>>
>>>How can I suppress that output is printed?
>>
>>If you don't want it printed, then why the <expletive deleted>
>>are you (explicitly!) using print???   Words fail me!!!
>>
>>	cheers,
>>
>>		Rolf Turner
>
>
>Because I don't get html code when I only use xtable(xy)
>
>
>
>>
>>######################################################################
>>Attention: This e-mail message is privileged and confidential. If 
>>you are not the intended recipient please delete the message and 
>>notify the sender. Any views or opinions presented are solely those 
>>of the author.
>>
>>This e-mail has been scanned and cleared by MailMarshal 
>>www.*marshalsoftware.com
>>######################################################################
>
>______________________________________________
>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.


-- 
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062




More information about the R-help mailing list