You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让remotes::install_local()忽略DESCRIPTION中Remotes的远程仓库地址

问题背景

我有两个R包packageone和packagetwo,其中packagetwo依赖packageone,并在其DESCRIPTION文件中通过Remotes字段指定了packageone的远程仓库地址:

Remotes:
    git::http://url/to/packageone.git

由于公司政策限制,同事无法访问这两个包的远程仓库,于是我将两个包的仓库打包后让同事用remotes::install_local()本地安装:

remotes::install_local("path/to/packageone", upgrade = "never")
remotes::install_local("path/to/packagetwo", upgrade = "never")

但即便packageone已经成功安装,安装packagetwo时仍报错——remotes::install_local()仍会尝试访问DESCRIPTION里指定的远程仓库地址,错误信息如下:

Error: Failed to install 'packagetwo' from local:
  Command failed (128)
In addition: Warning message:
In system(full, intern = TRUE, ignore.stderr = quiet) :
  running command ''/usr/bin/git' ls-remote http://url/to/packageone.git  2>/dev/null' had status 128 and error message 'Function not implemented'

注:此行为是remotes包的有意设计。

需求:在保留packagetwo的CRAN依赖安装功能的前提下,让remotes::install_local()忽略DESCRIPTION中Remotes指定的远程仓库地址。

解决方案

以下几种方法可解决问题,且均能保留packagetwo的CRAN依赖安装能力:

方法1:临时修改DESCRIPTION文件

安装packagetwo前,临时注释或删除其DESCRIPTION文件中的Remotes字段,安装完成后可按需恢复:

  1. 打开本地packagetwo文件夹下的DESCRIPTION文件
  2. 将Remotes部分注释:
# Remotes:
#    git::http://url/to/packageone.git
  1. 执行本地安装:
remotes::install_local("path/to/packagetwo", upgrade = "never")
  1. (可选)安装完成后恢复原Remotes字段内容。

方法2:关闭依赖检查安装

若已确认packageone及所有CRAN依赖均已安装,可使用devtools的安装命令关闭依赖检查:

devtools::install_local("path/to/packagetwo", dependencies = FALSE, upgrade = "never")

注意:需确保所有依赖(含CRAN包)已提前安装,否则包可能无法正常运行。

方法3:通过环境变量忽略Remotes

利用remotes包支持的环境变量,强制忽略所有Remotes指定的远程依赖,无需修改DESCRIPTION:

  1. 安装前设置环境变量:
Sys.setenv(REMOTES_IGNORE_REMOTES = "true")
  1. 执行本地安装:
remotes::install_local("path/to/packagetwo", upgrade = "never")
  1. (可选)安装完成后清除该环境变量:
Sys.unsetenv("REMOTES_IGNORE_REMOTES")

此方法不会影响CRAN依赖的自动安装,remotes仍会正常处理CRAN上的依赖包。

内容的提问来源于stack exchange,提问作者mikeck

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 21:03:14