2

我正在运行以下代码,但由于某种原因,在循环charts.PerformanceSummary()内使用时for,它会尝试产生比通过循环的次数更多的输出。而一个简单的绘图功能似乎工作正常......

请参阅下面的 .Rmd 代码,然后是编织到 html 后创建的后续 .md 文件...

PLOT TEST
====

```{r}
suppressPackageStartupMessages(require(PerformanceAnalytics))
for(i in 1:5){
  charts.PerformanceSummary(xts(rnorm(i*1000,0.0001,0.0003),Sys.Date()-c((i*1000):1)))
}
```

```{r}
for(i in 1:5){
  plot(xts(cumprod(rnorm(i*1000,0.0001,0.0003)+1),Sys.Date()-c((i*1000):1)))
}
```

给出以下 .md 文件

PLOT TEST
====


```r
suppressPackageStartupMessages(require(PerformanceAnalytics))
for (i in 1:5) {
    charts.PerformanceSummary(xts(rnorm(i * 1000, 1e-04, 3e-04), Sys.Date() - 
   c((i * 1000):1)))
}
```

![plot of chunk unnamed-chunk-1](figure/unnamed-chunk-11.png) ![plot of chunk unnamed-chunk-1](figure/unnamed-chunk-12.png) ![plot of chunk unnamed-chunk-1](figure/unnamed-chunk-13.png) ![plot of chunk unnamed-chunk-1](figure/unnamed-chunk-14.png) ![plot of chunk unnamed-chunk-1](figure/unnamed-chunk-15.png) ![plot of chunk unnamed-chunk-1](figure/unnamed-chunk-16.png) 



```r
for (i in 1:5) {
    plot(xts(cumprod(rnorm(i * 1000, 1e-04, 3e-04) + 1), Sys.Date() - c((i * 
    1000):1)))
}
```

![plot of chunk unnamed-chunk-2](figure/unnamed-chunk-21.png) ![plot of chunk unnamed-chunk-2](figure/unnamed-chunk-22.png) ![plot of chunk unnamed-chunk-2](figure/unnamed-chunk-23.png) ![plot of chunk unnamed-chunk-2](figure/unnamed-chunk-24.png) ![plot of chunk unnamed-chunk-2](figure/unnamed-chunk-25.png) 

请注意第一个块如何尝试连接到 6 个输出图,但第二个块中只有 5 个输出图,尽管它们具有相同for (i in 1:5) {的代码位......

作为附加信息,以下是sessionInfo

sessionInfo() 
## R version 3.0.0 (2013-04-03)
## Platform: x86_64-apple-darwin10.8.0 (64-bit)
## 
## locale:
## [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] PerformanceAnalytics_1.1.0 xts_0.9-3                 
## [3] zoo_1.7-9                  knitr_1.2                 
## 
## loaded via a namespace (and not attached):
## [1] digest_0.6.3    evaluate_0.4.3  formatR_0.7     grid_3.0.0     
## [5] lattice_0.20-15 stringr_0.6.2   tools_3.0.0

编辑

我也只是自己运行了一行,并有一个半修复......但不是一个用于在同一个块中制作多个图表的......

下面是 .Rmd 脚本和 .md 输出

```{r}
charts.PerformanceSummary(xts(rnorm(1000,0.0001,0.0003),Sys.Date()-c((1000):1)))
```

```{r fig.keep='last'}
charts.PerformanceSummary(xts(rnorm(1000,0.0001,0.0003),Sys.Date()-c((1000):1)))
```

.md 输出

```r
charts.PerformanceSummary(xts(rnorm(1000, 1e-04, 3e-04), Sys.Date() - c((1000):1)))
```

![plot of chunk unnamed-chunk-4](figure/unnamed-chunk-41.png) ![plot of chunk unnamed-chunk-4](figure/unnamed-chunk-42.png) 



```r
charts.PerformanceSummary(xts(rnorm(1000, 1e-04, 3e-04), Sys.Date() - c((1000):1)))
```

![plot of chunk unnamed-chunk-5](figure/unnamed-chunk-5.png) 

编辑 2

正如@agstudy 所指出的,看起来 knitr 正在生成不必要的空白图像……有人知道如何删除它吗?

4

0 回答 0