【发布时间】:2017-03-16 15:38:44
【问题描述】:
我有一个通过message() 报告进度的函数。在正常使用情况下,这是可取的,如果需要,可以通过suppressMessages() 抑制消息。
但是,我正在编写一个调用此函数的小插图(在 Rmarkdown 中),结果包括这些进度更新的完整页面。我想包括前几行消息,但不要浪费一整页。有没有办法配置这个?
我尝试过传递块选项R.options=list(max.print=10)、as suggested in another answer here,但这似乎不适用于消息。或者至少,不是在这种情况下,实际消息在每个函数中一次生成一个或两个,但该函数被称为循环的一部分。
我正在使用的一般结构是:
function1 <- function(file.list){
res <- list()
for(i in seq_along(file.list)){
message("processing ", file.list[i])
res[i] <- function2(file.list[i])
}
}
function2 <- function(file){
message("analyzing ", file)
tryVal <- try(res <- analysisFunction(file), silent = TRUE)
if(inherits(tryVal, "try-error")){
message("*** problem with ", file, " ***")
} else {
## additional processing
}
return(res)
}
markdown 块如下所示:
```{r batchFlowHist, R.options=list(max.print=10)}
batch1 <- function1(flowPloidyFiles)
```
我希望我的小插图显示来自已处理的前几个文件的消息,但不是整个循环。有没有办法做到这一点?
【问题讨论】: