我之前也遇到過這個問題,而且我發現最可靠的解決方案是使用來自夢幻般的[devtools] [1]軟件包的微小修改source_url
。這適用於我(在Mac上)。
load_url <- function (url, ..., sha1 = NULL) {
# based very closely on code for devtools::source_url
stopifnot(is.character(url), length(url) == 1)
temp_file <- tempfile()
on.exit(unlink(temp_file))
request <- httr::GET(url)
httr::stop_for_status(request)
writeBin(httr::content(request, type = "raw"), temp_file)
file_sha1 <- digest::digest(file = temp_file, algo = "sha1")
if (is.null(sha1)) {
message("SHA-1 hash of file is ", file_sha1)
}
else {
if (nchar(sha1) < 6) {
stop("Supplied SHA-1 hash is too short (must be at least 6 characters)")
}
file_sha1 <- substr(file_sha1, 1, nchar(sha1))
if (!identical(file_sha1, sha1)) {
stop("SHA-1 hash of downloaded file (", file_sha1,
")\n does not match expected value (", sha1,
")", call. = FALSE)
}
}
load(temp_file, envir = .GlobalEnv)
}
我用一個非常類似的修改,從使用read.table
github上,等拿到文本文件請注意,您需要使用GitHub的URL的「原始」版本(你在你的問題包括在內)。
[1] https://github.com/hadley/devtoolspackage
感謝發佈。我嘗試了上述解決方案,但收到以下消息。我嘗試了幾個不同的文件。錯誤:壞恢復文件幻數(文件可能已損壞) - 沒有數據加載 此外:警告消息: 文件'filef00b79947a46'有幻數'' 使用2之前的保存版本已被棄用 – markthekoala