Skip to content

Instantly share code, notes, and snippets.

Created July 12, 2017 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/d907700b3bee1b597a617329034411ad to your computer and use it in GitHub Desktop.
Save anonymous/d907700b3bee1b597a617329034411ad to your computer and use it in GitHub Desktop.
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
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