knitr - embedded HTML tags being escaped - how to turn off

14 views
Skip to first unread message

Robert Schuff

unread,
Mar 15, 2015, 1:40:32 PM3/15/15
to kn...@googlegroups.com
Hi,

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?

Thanks in advance!

Version and code example below:

RStudio - 0.98.1103
R - 3.13
knitr - 1.9

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")

Yihui Xie

unread,
Mar 16, 2015, 12:08:33 AM3/16/15
to Robert Schuff, knitr
You did the right thing to ask on StackOverflow:
http://stackoverflow.com/q/29064174/559676 :)

Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Web: http://yihui.name
Reply all
Reply to author
Forward
0 new messages