使用“R CMD INSTALL"时如何安装依赖项安装 R 包? [英] How to install dependencies when using "R CMD INSTALL" to install R packages?
问题描述
我正在开发我的第一个 R 包(使用 R 2.13、Ubuntu 10.10).我们称它为 foo 并假设 R/目录中的代码以行 library(bar) 开头,其中 bar 是现有的foo 依赖的 CRAN 中的包.我的说明文件包含以下行:
I'm developing my first R package (using R 2.13, Ubuntu 10.10). Let's call it foo and let's say that the code in the R/ directory begins with the line library(bar), where bar is an existing package, in CRAN, on which foo depends. My DESCRIPTION file contains the line:
Depends: bar
当包 foo 准备好进行测试时,我使用以下命令在本地安装它:
When package foo is ready for testing, I install it locally using:
R CMD INSTALL foo_1.0.tar.gz
但是,如果没有安装bar,我看到了:
However, if bar is not installed, I see:
ERROR: dependency ‘bar’ is not available for package ‘foo’
显然,如果我的 foo 是使用 install.packages() 从 CRAN 安装的,bar 将同时安装.所以我的问题是:当我使用 R CMD INSTALL 安装我的包 foo 时,如何确保安装了 CRAN 包 bar?这是配置脚本的工作吗?
Obviously, if my foo were installed from CRAN using install.packages(), bar would be installed at the same time. So my question is: how can I ensure that CRAN package bar is installed, if required, when I install my package foo using R CMD INSTALL? Is this a job for a configuration script?
推荐答案
其实重读R扩展指南,并没有说R CMD INSTALL会从CRAN获取依赖.R 中的 install.packages() 方法会这样做,但乍一看我不认为 R CMD INSTALL 会这样做.
Actually, re-reading the R extensions guide, it doesn't say that R CMD INSTALL will get dependencies from CRAN. The install.packages() method from within R will do that, but at first glance I don't think R CMD INSTALL does.
您可以使用 install.packages 从 .tar.gz 安装,但您必须设置 repos=NULL,然后这适用:
You can use install.packages to install from a .tar.gz, but you have to set repos=NULL, and then this applies:
dependencies: logical indicating to also install uninstalled packages
on which these packages depend/suggest/import (and so on
recursively). Not used if repos = NULL.
我怀疑要做的事情是从DESCRIPTION文件中取出依赖项,然后在干净的环境中测试构建时运行R并对其执行install.packages().
I suspect the thing to do is to get the dependencies out of the DESCRIPTION file and then run R and do an install.packages() on those when you are testing your build in a clean environment.
这篇关于使用“R CMD INSTALL"时如何安装依赖项安装 R 包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!