I am having a little trouble with knitr and embedded html tables. Basically what is happening is when I embed xtable output in html, the html tags are being escaped rending the output unreadable. the output of print.xtable does seems to correctly produce the expected output (an html table) but then when knit is called on the document that xtable is embedded into, escaped characters are produced. Does anybody have a solution?
library("knitr")
library("xtable")
# clear the console
cat("\014")
col1 <- c(1, 2, 3)
col2 <- c("a", "b", "c")
col3 <- c(TRUE, FALSE, TRUE)
df <- data.frame(col1, col2, col3)
df
tbl <- print(xtable(df),type="HTML",include.rownames=FALSE)
testknitr <- "<html>
<head>
<title>Test Knitr from variable</title>
</head>
<body>
<h1>Testing Knitr escaping </h1>
<table>
<tr>
<td>
<!--begin.rcode label=\"a table\"
tbl
end.rcode-->
</td>
</tr>
</table>"
knit(text=testknitr, output="testknitr.html")