如何告诉CRAN自动安装软件包依赖?

83

我在R中开发了一个软件包,当我在本地计算机上检查和构建它时,它能正常工作。但是,当我在CRAN上尝试时,会出现一个软件包依赖性错误。 我的软件包依赖于其他软件包中的两个函数。

如果我使用Dependsimportsdescription下列出其他软件包,那么这些软件包是否会自动安装到新软件包中?还是我需要在使用其他软件包的函数下显式调用install.packages("packagename")函数。如果这些都不正确,那么解决R中软件包依赖性的最佳方法是什么,以通过R CMD checkbuild测试并提交到CRAN?

谢谢。


6
在您的DESCRIPTION文件中,Depends:后面列出其他软件包。 - Anthony Damico
1
一个简单的测试方法是从您的系统中删除软件包X,然后查看您的软件包是否从依赖项中安装了X - csgillespie
2个回答

91

在您自己的系统上,请尝试

install.packages("foo", dependencies=...)

使用dependencies=参数被记录为

dependencies: logical indicating to also install uninstalled packages
      which these packages depend on/link to/import/suggest (and so
      on recursively).  Not used if ‘repos = NULL’.  Can also be a
      character vector, a subset of ‘c("Depends", "Imports",
      "LinkingTo", "Suggests", "Enhances")’.

      Only supported if ‘lib’ is of length one (or missing), so it
      is unambiguous where to install the dependent packages.  If
      this is not the case it is ignored, with a warning.

      The default, ‘NA’, means ‘c("Depends", "Imports",
      "LinkingTo")’.

      ‘TRUE’ means (as from R 2.15.0) to use ‘c("Depends",
      "Imports", "LinkingTo", "Suggests")’ for ‘pkgs’ and
      ‘c("Depends", "Imports", "LinkingTo")’ for added
      dependencies: this installs all the packages needed to run
      ‘pkgs’, their examples, tests and vignettes (if the package
      author specified them correctly).

所以你可能想要一个值TRUE

在你的包中,列出Depends:中需要什么,在编写R扩展手册中已经很清楚地说明了。


1
@dirk,谢谢。但是现在我知道问题出在哪里了。当我在R-forge上运行R CMD check时,它在linux-x86-64平台上出现了包依赖错误。但是在windowsmac操作系统上没有错误。错误信息看起来像这样:`using platform: x86_64-unknown-linux-gnu (64-bit)
  • checking package dependencies ... ERROR Packages required but not available: ‘isa2’ ‘fabia’`
- Mikael
1
如果我删除了一个软件包呢?我想删除所有它的依赖项,只要它们不是其他已安装软件包所需的。 - 7kemZmani
2
@andi:通常情况下并不是那么简单。如果依赖项需要在您的平台上进行编译(或者如果CRAN坚持下载源代码版本,即使其他地方可能有二进制分发版本),则安装依赖项可能会失败。例如,xgboost 以前就因此而臭名昭著。 - smci

5
另一种可能性是在R软件包安装程序的右下方选择“安装依赖项”复选框:

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接