使用knitr时如何删除xtable中的HTML标记?

时间:2015-09-23 14:32:57

标签: html r hyperlink knitr xtable

当我使用以下代码测试xtable以打印到单独的HTML文档时,它可以正常工作。

print(MyXtable, type = "html", file = "test.html", sanitize.text.function = force) 

但是,当我尝试在knitr中的R chunk中打印相同的xtable时,带有html标签的整个字符串将打印在xtable中。有人可以请他解释一下吗?这是我的Rchunk代码。

```{r MyXTable, results = 'asis', echo = FALSE, message=F, warning=F}  

MyTable <- data.frame(
                    paste0('<a href="https://mywebsite/', Data$ID, '"target=_blank>Go to Website</a>'),
                    Data$Task,
                    Data$Date
                    )

library(xtable)  
MyXtable<- xtable(MyTable)  
print(MyXtable, include.rownames=FALSE, type = "html",sanitize.text.function = force)

```

1 个答案:

答案 0 :(得分:0)

我明白了。我错过了以下论点:&#34;评论= FALSE&#34;

```{r MyXTable, results = 'asis', echo = FALSE, message=F, warning=F}  

MyTable <- data.frame(
                paste0('<a href="https://mywebsite/', Data$ID, '"target=_blank>Go to Website</a>'),
                Data$Task,
                Data$Date
                )

library(xtable)  
MyXtable<- xtable(MyTable, comment = FALSE)  
print(MyXtable, include.rownames=FALSE, type = "html",sanitize.text.function = force)

```