Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Catch errors and warnings from log file
#' Download a file
#' Test error with
#' downloadfile2("xxxx")
#' @param url an url
#' @param destfile, destination file
downloadfile2 <- function(url, destfile,...){
downloadstatus <- 1
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment