[R] Questions about xtable and print.xtable

Charilaos Skiadas skiadas at hanover.edu
Tue Jan 23 03:50:42 CET 2007

I have been using the wonderful xtable package lately, in combination  
with Sweave, and I have a couple of general questions along with a  
more particular one.

I'll start with the particular question. I basically have a 1x3 array  
with column names but no row names. I want to create a latex table  
with column setting set to "|rrr|". I want the column names to  
appear, but the row names not to appear. The code I am trying is this:

x <- matrix(c(1:3), c(1,3), dimnames=list(NULL,c(1:3)))
tab <- xtable(x, align="|rrrr|")
print.xtable(tab, include.rownames=FALSE)

The problem here is that the xtable call requires an align value that  
has one extra row setting, I suppose to account for a possible row  
name. However, the first print.xtable call seems to ignore the align  
argument set in the xtable call, when include.rownames is included.  
Any workarounds will be most welcomed.

More generally, I have the following questions:
1) Why are the include.rownames and include.colnames parameters not  
appearing in the xtable call, but only in the print.xtable call  
instead? Why do I need to specify n+1 arguments for things like align  
and digits, when I don't want the row names to be printed? In  
general, why are the align and digits calls not setable in  
print.xtable, but only in xtable?
2) I like to enclose my tabular environments in a center environment,  
instead of a table environment. Unless I've missed it, I don't see  
how I can do that from within the xtable package. Is this really not  
possible, and if so why not? The latex.environments setting seems to  
only be allowed when floating=TRUE, which is exactly what I want to  
avoid. Any particular reason it is not allowed when floating=FALSE as  

That's it really, thanks in advance for any responses.


More information about the R-help mailing list