【问题标题】:How do I remove HTML tags inside an xtable when using knitr?使用knitr时如何删除xtable中的HTML标签?
【发布时间】:2015-09-23 14:32:57
【问题描述】:

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

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

但是,当我尝试在 knitr 的 R 块中打印相同的 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)

```

【问题讨论】:

    标签: html r hyperlink knitr xtable


    【解决方案1】:

    我想通了。我错过了以下论点:“comment = FALSE”

    ```{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)
    
    ```
    

    【讨论】:

      猜你喜欢
      • 2014-08-15
      • 2013-12-04
      • 1970-01-01
      • 2018-06-29
      • 2019-11-29
      • 1970-01-01
      • 1970-01-01
      • 2015-08-12
      • 2011-05-19
      相关资源
      最近更新 更多