【问题标题】:supress error message of download.file function抑制 download.file 函数的错误消息
【发布时间】:2020-04-19 20:55:20
【问题描述】:

我想在 Rmarkdown 文档中抑制 download.file 函数的错误消息。我试过results="hide",message=F,echo=F,我试过invisiblesinksuppressWarningssuppressMessagesoptions(error = expression(NULL)),没有运气。 这是我的例子:

```{r,results="hide",message=F,echo=F}

tryCatch(download.file(paste0("https://www.kjqhfkpuc.es"),
                destfile = paste0("report.pdf"),mode = "wb",quiet = T),error = function(e) e)


```

我希望文档中没有输出

【问题讨论】:

    标签: r error-handling r-markdown


    【解决方案1】:

    options(warn = -1) 添加到代码块的开头将全局禁止警告。但是,最好在之后使用之前的警告设置重新打开警告。

    ```{r,results="hide",message=F,echo=F}
    
    oldw <- getOption("warn")
    options(warn = -1)
    tryCatch(download.file(paste0("https://www.kjqhfkpuc.es"),
                destfile = paste0("report.pdf"),mode = "wb",quiet = T),error = function(e) e)
    
    options(warn = oldw)
    
    ```
    

    this question

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-20
      • 1970-01-01
      • 1970-01-01
      • 2013-10-07
      • 1970-01-01
      相关资源
      最近更新 更多