我之前也遇到过这个问题,而且我发现最可靠的解决方案是使用来自梦幻般的[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