在针织机中,没有用于平移for循环的输出 [英] In knitr, no output from pander in for loop
本文介绍了在针织机中,没有用于平移for循环的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在RStudio中使用knitr时,在for循环中,pander不会产生任何(或正确的)html输出.这是一个最小的情况,作为Rmd输入文件.
Using knitr in RStudio, pander does not produce any (or correct) html output when in a for loop. Here is a minimal case, as an Rmd input file.
---
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,也观察到了相同的行为.
The result is the same for other (more interesting) "summary" objects, e.g. a summary of an lm fit. The same behavior was observed for pander 0.5.2 from CRAN, and also 0.5.3 loaded from github.
RStudio v 0.99.467.
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在评论中回答:
@daroczig answered in the comments :
- 在全局级别
knitr::opts_chunk$set(results="asis")
或块级别```{r,results="asis"}
上将knitr块选项results
更改为asis
- 禁用
panderOption
knitr.auto.asis
:panderOptions('knitr.auto.asis', FALSE)
- change knitr chunk option
results
toasis
, either at the global levelknitr::opts_chunk$set(results="asis")
or at the chunk level```{r,results="asis"}
- disable
panderOption
knitr.auto.asis
:panderOptions('knitr.auto.asis', FALSE)
Cf. 此问题
---
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))
```
这篇关于在针织机中,没有用于平移for循环的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文