我認爲它實際上是打印出來,如果我這樣做:
library(shiny)
validate(need(try(sd <- read.csv(file = "mtcars1.csv",
stringsAsFactors = FALSE)),
Error reading the file !!!"))
產生:
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file 'mtcars1.csv': No such file or directory
Error: Error reading the file !!!
我得到這個 - 注意你的消息是在最後一行。
您可以supressWarnings
抑制警告這樣的:
library(shiny)
suppressWarnings(
+ validate(need(try(sd <- read.csv(file = "mtcars1.csv",
stringsAsFactors = FALSE)),
"Error reading the file !!!!")))
產生:
Error in file(file, "rt") : cannot open the connection
Error: Error reading the file !!!!
或者你可以用這個剿一切,但你的信息(使用的tryCatch
代替try
):
library(shiny)
suppressWarnings(
validate(need(tryCatch(sd <- read.csv(file = "mtcars1.csv",
stringsAsFactors = FALSE), error=function (e){}),
"Error reading the file !!!!")))
yielding
Error: Error reading the file !!!
謝謝。我認爲我的錯誤與讀取csv文件無關,但與其他內容無關。是的,它應該可以正常工作。 – athlonshi