Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

knitr, R Markdown, and xtable: xtable tables within HTML table

Tags:

html

r

knitr

xtable

Suppose I want to print HTML tables using xtable, side-by-side. I tried doing this in an .Rmd file with:

<table border = 1>
<tr>
<td>
`r functionThatPrintsAnHTMLTableUsingxtable`
</td>
<td>
`r functionThatPrintsAnotherHTMLTableUsingxtable`
</td>
</tr>
</table>

No dice. What am I doing wrong? Thanks.

like image 751
Brash Equilibrium Avatar asked Jan 28 '14 05:01

Brash Equilibrium


1 Answers

I think your code will work if you put results=asis in the chunk options.

<table border = 1>
<tr>
<td>
```{r results='asis', echo=FALSE}
  library(xtable)
  data(tli)
  print(xtable(tli[1:20, ]),type='html')
```
</td>
<td>
```{r results='asis', echo=FALSE}
  library(xtable)
  data(tli)
  print(xtable(tli[1:20, ]),type='html',comment=FALSE)
```
</td>
</tr>
</table>
like image 136
nograpes Avatar answered Oct 23 '22 12:10

nograpes