I finally got it. It was the xtable placed within the float that was causing the table error. Once I had realised that and got rid of the APA6 issue which was due to the fact that APA6 requires a title then it was fine. Thanks for all the help.
This is working fine <<atable,results="asis", echo=FALSE>>= library(xtable) data(tli) tli.table <- xtable(tli[1:20, ], caption = "An xtable example", label = "tab:A table") digits(tli.table)[c(2, 6)] <- 0 print(tli.table, caption.placement="top") @ One question though, you say "Use print.xtable(...,floating=F) to avoid this. Do you mean that if I want to place it with a LyX float that the code below should work? Currently it gives an error. <<atable,results="asis", echo=FALSE>>= library(xtable) data(tli) tli.table <- xtable(tli[1:20, ], caption = "An xtable example", label = "tab:A table") digits(tli.table)[c(2, 6)] <- 0 print(tli.table, caption.placement="top", floating=FALSE) @ ________________________________ From: Liviu Andronic <landronim...@gmail.com> To: John Kane <jrkrid...@yahoo.ca> Cc: Users LyX <lyx-users@lists.lyx.org> Sent: Friday, May 10, 2013 4:23:00 PM Subject: Re: Problem producing tables with knitr and xtable On Fri, May 10, 2013 at 8:55 PM, John Kane <jrkrid...@yahoo.ca> wrote: > I have been playing with LyX and knitr. I have had no problem generating > figures generally using ggplot2 I cannot get LyX to generate a table with > knitr and xtable. > See attached. Two issues: - You need to use chunk option results="asis" (similar to results=tex for Sweave) - By default xtable() outputs the table in a floating environment; it makes little sense to put that in a table float. Use print.xtable(..., floating=F) to avoid this. Liviu > The file table.knitr one is my last attempt to generate a table. Not a > success though there is something there. table.kniter2.lyx is a successful > example of my running the same code in R and then just cutting and pasting > the resulting LaTeX code (minus the \begin{table}[ht] & \end{table} of > course. > > Can anyone give me some pointers as to what I am doing wrong? I seem to > have spent about 2 hours trying to find some useful examples without much > success. > > Thanks. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail