I have the following R code:
tryCatch( {pre_symbol=read.table(file=filePre,header=FALSE,sep=",")}
, error = function(e) {loadError = TRUE} )
When the input file (filePre) is empty, the tryCatch does NOT set the global variable loadError to TRUE. This creates problems in my code (when code that executes when loadError==false assumes filePre is not empty) that the tryCatch was supposed to prevent. However, when I remove the tryCatch statement and try to load via read.Table, I get the error
Error in read.table(file = filePre, header = FALSE, sep = ",") : no lines available in input
which is expected in this case. I have no idea why this isn't working. It works for most of the other files in my set.
You should use global assignment operator <<-
here , for example:
loadError = FALSE
toto <- function(){
tryCatch(stop("dummy error"),error=function(e)loadError <<- TRUE)
}
> toto()
> loadError
[1] TRUE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With