我有一个报告进度的功能message().在正常使用下,这是可取的,并且suppressMessages()如果需要,可以通过消息来抑制消息.
但是,我正在编写一个调用此函数的插图(在Rmarkdown中),结果包括这些进度更新的完整页面.我想包括前几行消息,但不要浪费整整一页.有没有办法配置这个?
我已尝试传递chunk选项R.options=list(max.print=10),如此处的另一个答案所示,但这似乎不适用于消息.或者至少,不是在这种情况下,在每个函数内一次生成一个或两个实际消息,但该函数被称为循环的一部分.
我正在使用的一般结构是:
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)
}
Run Code Online (Sandbox Code Playgroud)
降价块看起来像这样:
```{r batchFlowHist, R.options=list(max.print=10)}
batch1 <- function1(flowPloidyFiles)
```
Run Code Online (Sandbox Code Playgroud)
我希望我的插图能够显示处理的前几个文件中的消息,而不是整个循环.有办法做到这一点吗?
事实证明,knitr已经通过message参数支持了这一点.链接的答案表明它不起作用,但由于发布了它必须已添加.所以以下解决了我的问题:
```{r batchFlowHist, message = 1:10}
batch1 <- function1(flowPloidyFiles)
```
Run Code Online (Sandbox Code Playgroud)