[R] xtable "longtable" with caption on "top"

Liviu Andronic landronimirc at gmail.com
Tue Aug 25 13:54:07 CEST 2009

Dear all
I would like to export a matrix to a LaTeX "longtable" environment
that would have its caption on top of the table. However xtable()
seems to bar me from doing this:
> print(xtable(mtcars[1:10,c(1,2)], caption="CARS"),
+ tabular.environment="longtable", caption.placement="top"
+ , floating=F)
% latex table generated in R 2.9.1 by xtable 1.5-5 package
% Tue Aug 25 13:48:01 2009
\begin{longtable}{rrr}
\hline
& mpg & cyl \\
\hline
Mazda RX4 & 21.00 & 6.00 \\
Mazda RX4 Wag & 21.00 & 6.00 \\
Datsun 710 & 22.80 & 4.00 \\
Hornet 4 Drive & 21.40 & 6.00 \\
Hornet Sportabout & 18.70 & 8.00 \\
Valiant & 18.10 & 6.00 \\
Duster 360 & 14.30 & 8.00 \\
Merc 240D & 24.40 & 4.00 \\
Merc 230 & 22.80 & 4.00 \\
Merc 280 & 19.20 & 6.00 \\
\hline
\hline
\caption{CARS}
\end{longtable}
Warning message:
In print.xtable(xtable(mtcars[1:10, c(1, 2)], caption = "CARS"),  :
Attempt to use "longtable" with caption.placement="top". Changing to "bottom".

The error seems strange since I would assume that "longtable" tables
would naturally have the caption at the beginning of the table,
especially if it streches over multiple pages. There is no such error
when caption.placement="bottom". Would this be a bug in xtable()?
Thank you
Liviu

--
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail