# Function to download remote file to the disk urlDownload <- function(urlLink, showProgress = FALSE) { urlHead <- curlGetHeaders(urlLink) fileSize <- as.numeric(gsub("^.*content-length: ([0-9]+).*$", "\\1", tolower(urlHead[5]))) fileName <- gsub("^.*filename=(.*)\r\n$", "\\1", urlHead[7]) if (!file.exists(fileName) || file.info(fileName)$size != fileSize) { if (showProgress) { message(sprintf('Downloading %s', fileName)) httr::GET(urlLink, httr::write_disk(fileName, overwrite = TRUE), httr::progress()) cat('\n') } else { httr::GET(urlLink, httr::write_disk(fileName, overwrite = TRUE)) } } return(fileName) }