[R] xtable() with booktabs option problem

Marc Schwartz marc_schwartz at me.com
Fri May 24 21:41:52 CEST 2013


On May 24, 2013, at 2:36 PM, John Kane <jrkrideau at inbox.com> wrote:

> I could have sworn that yesterday xtable(file, booktabs = TRUE) was giving me toprule , midrule and bottomrule outout. Today :
> 
> library(xtable)
> aa  <- table( sample(letters[1:9], 100, replace = TRUE))
>  xtable(aa, 
>         booktabs = TRUE)
> gives me
> 
> \begin{table}[ht]
> \centering
> \begin{tabular}{rr}
>  \hline
> & V1 \\ 
>  \hline
> a &  15 \\ 
>  b &  11 \\ 
>  c &  13 \\ 
>  d &  14 \\ 
>  e &  10 \\ 
>  f &  12 \\ 
>  g &  10 \\ 
>  h &   6 \\ 
>  i &   9 \\ 
>   \hline
> \end{tabular}
> \end{table}
> 
> What stunningly stupid thing am I doing?
> 
> John Kane
> Kingston ON Canada


John,

The 'booktabs' argument is for print.xtable(), not xtable(). Easy mistake.

Thus:

> print(xtable(aa), booktabs = TRUE)
% latex table generated in R 3.0.1 by xtable 1.7-1 package
% Fri May 24 14:40:07 2013
\begin{table}[ht]
\centering
\begin{tabular}{rr}
  \toprule
 & V1 \\ 
  \midrule
a &   9 \\ 
  b &   8 \\ 
  c &  17 \\ 
  d &   9 \\ 
  e &   7 \\ 
  f &  16 \\ 
  g &  13 \\ 
  h &  10 \\ 
  i &  11 \\ 
   \bottomrule
\end{tabular}
\end{table}


Regards,

Marc Schwartz



More information about the R-help mailing list