gpt4 book ai didi

r - 在针织机中,没有用于平移for循环的输出

转载 作者:行者123 更新时间:2023-12-03 03:20:09 24 4
gpt4 key购买 nike

在RStudio中使用knitr时,在for循环中,pander不会产生任何(或正确的)html输出。这是一个最小的情况,作为Rmd输入文件。

---
title: "Untitled"
output: html_document
---

Testing why pander doesn't work in for loop

```{r global_options, include=FALSE}
knitr::opts_chunk$set(fig.width=7, fig.height=5, echo=FALSE, warning=FALSE,
message=FALSE)

```

```{r}
library(pander)

r <- 1:10
print("pander at top level")
pander(summary(r)) # works

print("pander in for loop")
for (i in 1:2) pander(summary(r)) #does not work (nothing in output)
for (i in 1:2) print(pander(summary(r))) #does not work (code in output)
for (i in 1:2) print(summary(r)) # works

```

其他(更有趣的)“摘要”对象的结果是相同的,例如lm适合的摘要。对于来自CRAN的pander 0.5.2和从github加载的0.5.3也观察到了相同的行为。

RStudio v 0.99.467。
> sessionInfo()
R version 3.2.0 (2015-04-16)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.4 (Yosemite)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] pander_0.5.3

loaded via a namespace (and not attached):
[1] minqa_1.2.4 MASS_7.3-40 Matrix_1.2-0 htmltools_0.2.6 tools_3.2.0
[6] yaml_2.1.13 Rcpp_0.11.6 rmarkdown_0.7 splines_3.2.0 nlme_3.1-120
[11] grid_3.2.0 digest_0.6.8 nloptr_1.0.4 lme4_1.1-7 lattice_0.20-31

最佳答案

@daroczig在评论中回答:

  • 在全局级别results或块级别asis
  • 上,将knitr块选项 knitr::opts_chunk$set(results="asis")更改为 ```{r,results="asis"}
  • 禁用panderOption knitr.auto.asis:panderOptions('knitr.auto.asis', FALSE)

  • cf.
    this issue
    ---
    title: "Untitled"
    output: html_document
    ---

    Testing **when** pander doesn't work in for loop

    ```{r global_options, include=FALSE}
    knitr::opts_chunk$set(fig.width=7, fig.height=5, echo=TRUE, warning=FALSE,
    message=FALSE)

    ```

    ```{r,results="asis"}
    library(pander)
    panderOptions('knitr.auto.asis', FALSE)

    r <- 1:10

    for (i in 1:2) pander(summary(r))

    ```

    关于r - 在针织机中,没有用于平移for循环的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31626419/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com