TL;DR:这是可能的,请参阅下面的代码。
为了供任何人将来使用,这里有一种从私人 Github 存储库获取 R 脚本的方法,使用httr
,并且可选地,devtools
.
我进行了足够多的搜索,找到了解决方案的各个部分,然后将它们全部缝合在一起。因此,功劳归于多个其他线程和网站。
一些来源是here https://github.com/opetchey/RREEBES/wiki/Reading-data-and-code-from-an-online-github-repository, here https://gist.github.com/Integralist/9482061 and here https://stackoverflow.com/questions/35720660/how-to-use-an-r-script-from-github.
见下面的代码:
library(httr)
# Source R script from Github
script <-
GET(
url = "https://api.github.com/repos/{user_name}/{repo_name}/contents/{script_name}.R",
authenticate({github_email}, {github_personal_access_token}), # 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))
这可能仅适用于您拥有的私人存储库。我不确定它是否适用于与您共享的私人仓库。
请参阅此链接 https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line创建 Github 个人访问令牌 (PAT)。如果需要,您还可以将其保存为 R 中的环境变量。devtools::github_pat()
在这里很有用。
您的电子邮件和 PAT(或密码)都需要用引号引起来。