Rmarkdown 未呈现原始 HTML

Rmarkdown not rendering raw HTML

Rstudio 升级到 1.4 版本后,渲染这个 rmarkdown 文档时

---
title: "Raw HTML"
output: html_document
---

```{r setup, include=FALSE}
library(knitr)
library(htmltools)
knitr::opts_chunk$set(echo = F)
```

```{r}
f <- function(text){
   cat(asis_output(htmltools::htmlPreserve(paste("<span style=\"color:green\">", text, "</span>"))))
   return(0)
}
```

```{r}
x <- f('Hello!')
```

我得到这个 html 文档

但在更新之前,此代码按预期工作,呈现此 html 文档

如何获得第二个 html 文档?

cat 删除 knit_asis class.
您可以避免 cat 或使用 results='asis' chunck 选项:

---
title: "Raw HTML"
output: html_document
---

```{r setup, include=FALSE}
library(knitr)
library(htmltools)
knitr::opts_chunk$set(echo = F)
```

```{r}
side.effect <- function(text){
   cat(asis_output(htmltools::htmlPreserve(paste("<span style=\"color:green\">", text, "</span>"))))
  return(0)
}

direct <- function(text){
   asis_output(htmltools::htmlPreserve(paste("<span style=\"color:green\">", text, "</span>")))
}
```


```{r}
direct('direct Hello!')
```

```{r,results ='asis'}
x <- side.effect('side effect Hello!')
```