Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

knitr doesn't convert xtable output on R 3.0.2

Tags:

r

knitr

xtable

I would like to create a tex table using xtable(). Here's my minimal example which worked when I used the same R version on Win 7.

\documentclass[a4paper,12pt,twoside]{article}

\begin{document}

<<load-packages,include=TRUE,echo=TRUE>>=
library(xtable)
@

<<testing-xtable,echo=TRUE,cache=FALSE,include=TRUE>>=
tab <- matrix(1:50,nrow=10)
rownames(tab) <- letters[1:10]

print(
  xtable(
    x=tab,
    caption="A table",
    label="tab",
    align=rep("c",times=6),
    digits=3,
    display=rep("f",times=6)
    ), 
  sanitize.colnames.function=identity,
  include.rownames=FALSE,
  table.placement="h"
  )
@
\end{document}

Instead of a nice table I get the verbatim code output of xlatex() in the pdf document.

Here's the output of knitr:

> grDevices::pdf.options(useDingbats = FALSE); require(knitr); opts_knit$set(concordance     = TRUE); knit('xtable.Rnw', encoding='UTF-8')
Loading required package: knitr


processing file: xtable.Rnw
  |.............                                                    |  20%
  ordinary text without R code

  |..........................                                       |  40%
label: load-packages (with options) 
List of 2
 $ include: logi TRUE
 $ echo   : logi TRUE

  |.......................................                          |  60%
  ordinary text without R code

  |....................................................             |  80%
label: testing-xtable (with options) 
List of 3
 $ echo   : logi TRUE
 $ cache  : logi FALSE
 $ include: logi TRUE

  |.................................................................| 100%
  ordinary text without R code


output file: xtable.tex

[1] "xtable.tex"
> 
> 
Running pdflatex on xtable.tex...completed

Created PDF:             ~/Dropbox/intern/sandbox(coding)/tex/chapter/chapter/sandbox/xtable/xtable.pdf

Issues: 2 badboxes

The code chunk testing-xtable should be echoed in the final document but it isn't. This is the pdf output. I'm suspicious about the message Ordinary text without R code. Is this normal?

Any help would be greatly appreciated.

like image 720
Gerome Bochmann Avatar asked Jan 31 '14 14:01

Gerome Bochmann


1 Answers

Use the chunk option results='asis'.

like image 147
Yihui Xie Avatar answered Nov 08 '22 23:11

Yihui Xie