我想从私有(private) gitlab 服务器中获取 .R 文件。我需要使用用户/密码的基本身份验证
我尝试了这种指令但没有成功
httr::GET("http://vpsxxxx.ovh.net/root/project/raw/9f8a404b5b33c216d366d80b7d48e34577598069/R/script.R",
authenticate("user", "password",type="basic"))
任何的想法?
问候
编辑:我找到了这种方式...但我需要下载所有项目...
bundle <- tempfile()
git2r::clone("http://vpsxxx.ovh.net/root/projet.git",
bundle, credentials=git2r::cred_user_pass("user", "password"))
source(file.path(bundle,"R","script.R"))
最佳答案
您可以使用 gitlab API 从存储库中获取文件。 gitlabr
可以帮助你做到这一点。当前版本 0.9 与 apiV3 和 V4 兼容。
这应该可以工作(它可以在我使用 apiv3 的私有(private) gitlab 上工作)
library(gitlabr)
my_gitlab <- gl_connection("https://private-gitlab.com",
login = "username",
password = "password",
api_version = "v4") # by default. put v3 here if needed
my_file <- my_gitlab(gl_get_file, project = "project_name", file_path = "path/to/file")
这将为您提供文件的字符版本。您还可以取回原始版本以另一种方式处理它。
raw <- gl_get_file(project = "project_name",
file_path = "file/to/path",
gitlab_con = my_gitlab,
to_char = F)
temp_file <- tempfile()
writeBin(raw, temp_file)
您现在可以获取代码
source(temp_file)
这是其中的一种解决方案。在不使用 API 的情况下,我无法获得文件的来源。
我知道 :
* 您可以使用访问 token 代替用户名和密码
* 您可以使用
gitlabr
几种方式。它记录在小插图中。我在这里使用了两种不同的方式。* 1.0 版将不兼容 v3 api。但我认为您使用的是 v4。
如果需要更明确的答案,请随时回复我,以便我更新这篇文章。
关于r - 来自具有基本身份验证的私有(private) gitlab 的源 R 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42747710/