r - 来自具有基本身份验证的私有(private) gitlab 的源 R 文件

标签 r gitlab

我想从私有(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/

相关文章:

linux - 无法以普通用户身份推送到 git 存储库

linux - 在 Linux 中运行 R 时出错

r - 什么是 R 中的整数溢出,它是如何发生的?

r - 带多个孔的 geom_polygon

r - 将 data.tables 的不同子集导出到集群中的每个节点

docker - 如何提取 docker 镜像的所有替代标签?

Gradle 仅在 CI 工作期间提示缺少 jar

windows - 为什么gitea添加了ssh还需要密码登录?

r - for循环遍历数据框列表并将结果保存在新数据框中

git - 初始推送到新的远程 git 存储库