1`quantmodVersion` <- function() { 2 return(list(Version='0.3-7', Revision=433)) 3} 4 5`quantmodNews` <- function() { 6 7} 8 9`quantmodChanges` <- function() { 10 11} 12 13`quantmodBugs` <- function() { 14 15} 16 17`quantmodComment` <- function() { 18 19} 20 21`quantmod.com` <- function() { 22 browseURL('http://www.quantmod.com') 23} 24 25`try.download.file` <- 26function(url, destfile, method, quiet = FALSE, mode = "w", cacheOK = TRUE, 27 extra = getOption("download.file.extra"), ...) 28{ 29 # no longer used 30 # appears to have only been callled by getSymbols.FRED() to handle https 31 # downloads that are now handled by curl 32 # leaving in place in case needed for some other scenario 33 34 if (missing(method)) 35 method <- getOption("download.file.method", default="auto") 36 37 # capture download.file errors (e.g. https not supported) 38 try.download <- try({ 39 download.file(url, destfile, method, quiet, mode, cacheOK, extra) 40 }, silent=TRUE) 41 42 if (inherits(try.download, "try-error")) { 43 if (requireNamespace("downloader", quietly=TRUE)) { 44 # use downloader::download, if available 45 # everything except 'url' is passed via '...', so name them; and 46 # download automatically determines 'method' and errors if supplied 47 # as an argument, so omit it 48 downloader::download(url, destfile=destfile, quiet=quiet, 49 mode=mode, cacheOK=cacheOK, extra=extra) 50 } else { 51 # report original error, and provide recommendations 52 errcond <- attr(try.download, "condition") 53 stop("Failed to download file. Error message:\n", errcond$message, "\n", 54 "If this is related to https, possible solutions are:\n", 55 "1. Explicitly pass method= via the getSymbols call (or via setDefaults)\n", 56 "2. Install downloader, which may be able to automagically determine a method\n", 57 "3. Set the download.file.method global option", call.=FALSE) 58 } 59 } 60} 61 62retry.yahoo <- 63function(symbol, 64 from, 65 to, 66 interval, 67 type, 68 conn, 69 ..., 70 curl.options = list()) 71{ 72 warning(symbol, " download failed; trying again.", 73 call. = FALSE, immediate. = TRUE) 74 75 # re-create handle 76 handle <- .getHandle(curl.options, force.new = TRUE) 77 78 # try again. must rebuild url with crumbs 79 yahoo.URL <- .yahooURL(symbol, from, to, interval, type, handle) 80 81 close(conn) 82 conn <- curl::curl(yahoo.URL, handle = handle$ch) 83 84 fr <- try(read.csv(conn, ..., as.is = TRUE), silent = TRUE) 85 86 # error if second attempt also failed 87 if (inherits(fr, "try-error")) { 88 close(conn) 89 stop(symbol, " download failed after two attempts. Error", 90 " message:\n", attr(fr, "condition")$message, call. = FALSE) 91 } 92 93 # return data 94 return(fr) 95} 96