Source_data R来自私人仓库。

问题描述 投票:0回答:1

我正试图从我的网站上读取一个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中从我的私人仓库读取这些数据?

r git github data-science httr
1个回答
0
投票

我可以解决这个问题。

  1. 在GitHub上生成你的个人令牌 1.1 进入GitHub 2.1 在右角进入 "设置" 2.2 然后在左边部分进入 "开发者设置" 2.3 选择 "个人访问令牌 "选项 2.4 选择 "生成新令牌" 2.5 复制你的个人令牌。
  2. 在您的主目录上 按照接下来的步骤 2.1 创建文件.Renviron
macbook@user:~$ touch .Reviron

在这个文件上写下你的个人密码,比如这样。

macbook@user:~$ nano .Reviron
GITHUB_PAT=YOUR PERSONAL TOKEN
  1. 现在,在R上,你可以用这个检查你的个人标识是否被保存。
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)

© www.soinside.com 2019 - 2024. All rights reserved.