在Rhtml(knitr)文档中使用图表_系列打印时避免空打印

在Rhtml(knitr)文档中使用图表_系列打印时避免空打印,r,knitr,quantmod,R,Knitr,Quantmod,我正在使用knitr生成一个带有嵌入式绘图的HTML文档。当chart_系列函数放置在循环中时,我遇到了问题。如果我指定fig.keep=“last”,我只得到最后一个图(三个图中的最后一个)。如果我选择fig.keep=“high”选项,我将在实际绘图之前获得空绘图。下面提供了一个简单的工作示例 <!--begin.rcode opts_chunk$set(echo=TRUE) opts_chunk$set(fig.align='center', fig.keep="high") o

我正在使用knitr生成一个带有嵌入式绘图的HTML文档。当chart_系列函数放置在循环中时,我遇到了问题。如果我指定fig.keep=“last”,我只得到最后一个图(三个图中的最后一个)。如果我选择fig.keep=“high”选项,我将在实际绘图之前获得空绘图。下面提供了一个简单的工作示例

<!--begin.rcode
opts_chunk$set(echo=TRUE) 
opts_chunk$set(fig.align='center', fig.keep="high") 
opts_chunk$set(dpi=150) 

library(xts)
library(quantmod)

data(sample_matrix)
s <- as.xts(sample_matrix)
end.rcode-->

<html>

<head>
<title>Title</title>
</head>

<body>

<h1>One plot</h1>

<!--begin.rcode
print(chart_Series(s))
end.rcode-->
<h1>Three plots</h1>

<!--begin.rcode
for (i in seq(1:3)) {
  print(chart_Series(s))
}
end.rcode-->
</body>
</html>

标题
一块地
三块地

如何消除开始时的“空”图?

如评论所示,这是已发布的evaluate包的一个缺陷。将来,它将出现在CRAN上的评估(>=0.5.7)中。现在,你可以

devtools::install_github('hadley/evaluate')

在evaluate包的开发版本中,我可能会遇到这个问题;请尝试
devtools::install\u github('hadley/evaluate')
。谢谢,它工作起来很有魅力!