Created
July 12, 2017 08:38
-
-
Save anonymous/d907700b3bee1b597a617329034411ad to your computer and use it in GitHub Desktop.
Catch errors and warnings from log file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Download a file | |
#' Test error with | |
#' downloadfile2("xxxx") | |
#' @param url an url | |
#' @param destfile, destination file | |
downloadfile2 <- function(url, destfile,...){ | |
downloadstatus <- 1 | |
tryCatch({ | |
# Store the download status returned by download.file | |
downloadstatus <- download.file(url = url, destfile = destfile, ...) | |
}, error = function(errorcondition){ | |
# Add error message to the log file | |
write(toString(errorcondition), logfile, append=TRUE) | |
}, warning = function(warningcondition){ | |
# Add warning message to the log file | |
write(toString(warningcondition), logfile, append=TRUE) | |
} | |
) | |
# Returns the download status | |
invisible(downloadstatus) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment