小编seb*_*eau的帖子

从lapply或使用print语句从函数调用时,kable的意外行为

我正在尝试理解使用knitr包编织HTML时在kable函数中的两个意外行为(在Ubuntu 14.04上的RStudio 0.98.977中):

  1. 当从lapply内部进行两次kable调用时,只有第一次调用在最终的HTML中产生漂亮的显示.
  2. 当在一个也使用print语句的函数中进行两次kable调用时,只有最后一次调用才会在最终的HTML中产生漂亮的显示.

示例代码如下:

Load library:

```{r init}
library("knitr")
```

Define dataframe:

```{r define_dataframe}
df <- data.frame(letters=c("a", "b", "c"), numbers=c(1, 2, 3))
rownames(df) <- c("x", "y", "z")
```

### Example 1: pretty display with simple call

The dataframe is displayed nicely twice when knitting HTML with the following code:

```{r pretty_display1, results="asis"}
kable(df)
kable(df)
```

### Example 2: unexpected display with lapply

The dataframe is displayed nicely only the first time when knitting HTML with the following code: …
Run Code Online (Sandbox Code Playgroud)

r lapply rstudio knitr

8
推荐指数
1
解决办法
1879
查看次数

标签 统计

knitr ×1

lapply ×1

r ×1

rstudio ×1