我正试图从我的网站上读取一个RD数据文件。私人 储存库
library(repmis)
source_data("https://github.com/**********.Rdata?raw=true")
这是我的输出
Error in download_data_intern(url = url, sha1 = sha1, temp_file = temp_file) :
Not Found (HTTP 404).
其他方式
script <-
GET(
url = "https://api.github.com/repos/***/data/contents/01-wrangle-data-covid-ssa-mx-county.R",
authenticate(Sys.getenv("GITHUB_PAT"), ""), # Instead of PAT, could use password
accept("application/vnd.github.v3.raw")
) %>%
content(as = "text")
# Evaluate and parse to global environment
eval(parse(text = script))
有谁知道我怎么能在R中从我的私人仓库读取这些数据?
我可以解决这个问题。
macbook@user:~$ touch .Reviron
在这个文件上写下你的个人密码,比如这样。
macbook@user:~$ nano .Reviron
GITHUB_PAT=YOUR PERSONAL TOKEN
Sys.getenv("GITHUB_PAT")
你也可以用这个在R上编辑你的token。
usethis::edit_r_environ()
不要忘记重启R来保存你的修改。
3. 最后,在R上,这些代码将从私人仓库加载你的数据。
library(httr)
req <- content(GET(
"https://api.github.com/repos/you_group/your_repository/contents/your_path_to your_doc/df_test.Rdata",
add_headers(Authorization = "token YOUR_TOKEN")
), as = "parsed")
tmp <- tempfile()
r1 <- GET(req$download_url, write_disk(tmp))
load(tmp)