如何阻止 fread 在 trycatch 中显示消息

How to stop fread from displaying messages when it is inside trycatch

我想制作一个函数,如果存在 csv 文件则加载该文件,否则使用数据库连接构建它。我想到了使用trycatch然后fread里面如下:

library(data.table)
res <- tryCatch({fread(input="filename.csv",sep=";");},
   error = function(err){return("error")} ,
   warning = function(war){return("error")} ,silent=TRUE)

if("character" %in% class(res)){print("Build the file anew")}

我希望它保持静音,即不显示任何消息。但是我得到:

Der Befehl "filename.csv" ist entweder falsch geschrieben oder konnte nicht gefunden werden.

(德语的应用程序)并且只有在 if 部分运行之后。有没有办法抑制这条消息?

我试过了,data.table 1.9.4 我得到了:

The system cannot find the path specified.

(我猜这是你长长的德语句子的执行摘要;))

data.table 版本 1.9.6 中,它按预期工作。所以只需更新您的软件包:

update.packages()

你应该没事。