Final message output when knitting R in PDF

I have a function that reports progress through message(). Under normal use, this is desirable, and messages can be suppressed using suppressMessages()if necessary.

However, I am writing a vignette (in Rmarkdown) that calls this function, and the results include a full page of these progress updates. I would like to include the first few lines of messages, but not spend a whole page on them. Is there any way to configure this?

I tried to convey chunk option R.options=list(max.print=10), as suggested in another answer here , but it does not seem to apply to messages. Or, at least not in this context, where the actual messages are generated one or two at a time in each function, but this function is called part of the loop.

The general structure I work with:

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)
}

The markdown block is as follows:

```{r batchFlowHist, R.options=list(max.print=10)}
batch1 <- function1(flowPloidyFiles)
```

I want my vignette to display messages from the first few processed files, but not the entire cycle. Is there any way to do this?

+4
source share
1 answer

, knitr message. , , , , . , :

```{r batchFlowHist, message = 1:10}
batch1 <- function1(flowPloidyFiles)
```
+5

Source: https://habr.com/ru/post/1672480/


All Articles