如何强制renv使用私有Artifactory仓库而非P3M获取指定R包版本?
强制renv仅从私有Artifactory仓库下载R包的问题
我正尝试强制renv从公司私有Artifactory仓库下载所有R包(包括特定归档版本),但renv会忽略配置,默认使用Posit Package Manager(P3M)快照获取部分包。
例如,即便做了大量配置,执行renv::install("jsonlite@1.8.8")时,日志显示仍从P3M下载:
# Downloading packages ------------------------------------------------------- - Downloading jsonlite from P3M ... # Downloading 'https://packagemanager.posit.co/cran/2024-09-20/bin/windows/contrib/4.4/jsonlite_1.8.8.zip'
我的目标是让所有包下载仅通过需Bearer Token认证的私有仓库进行。
当前配置
.Rprofile
local({ repo_url <- "https://my-private-repo.com/artifactory/cran" auth_token <- Sys.getenv("PRIVATE_REPO_ACCESS_TOKEN") auth_header <- c(Authorization = paste("Bearer", auth_token)) options(repos = c(PrivateRepo = repo_url)) options(install.packages.headers = auth_header) options(renv.config.transform.urls = FALSE) # Disable P3M redirection options(renv.download.headers = function(url) { if (grepl(paste0("^", repo_url), url)) return(auth_header) }) }) source("renv/activate.R") renv::config$repos.override("https://my-private-repo.com/artifactory/cran")
.Renviron
PRIVATE_REPO_ACCESS_TOKEN="my_actual_token_is_here" RENV_CONFIG_REPOS="https://my-private-repo.com/artifactory/cran" RENV_CONFIG_BINARY_REPOS="https://my-private-repo.com/artifactory/cran"
已尝试的无效方案
- 在.Renviron中设置
RENV_CONFIG_REPOS_OVERRIDE; - 在.Rprofile中设置
renv::config$repos.override(); - 设置
options(renv.config.transform.urls = FALSE); - 完全重置环境:删除项目的renv目录、renv.lock文件及全局renv缓存文件夹(
renv::paths$cache()),再执行renv::install(pkgs)重新安装。
如何彻底强制renv仅使用指定的私有仓库进行所有包安装?是否存在我遗漏的、优先级更高的配置项?
内容的提问来源于stack exchange,提问作者Baekjun Kim
相关产品推荐
相关产品推荐

