80

我在 R 中开发了一个包,当我在本地计算机中检查并构建它时,它可以正常工作。但是当我在 CRAN 中尝试它时,我得到一个包依赖项错误。我的包依赖于其他包的两个功能。

如果我在descriptionusingDepends或下列出其他包imports,它会自动与新包一起安装吗?或者我是否需要在install.packages("packagename")我使用过其他包的函数下显式调用该函数。如果这一切都错了,解决包依赖关系R以通过测试R CMD checkbuild提交给 CRAN 的最佳方法是什么?

谢谢你。

4

2 回答 2

86

在您自己的系统上,尝试

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:,请参阅 Writing R Extensions手册,这很清楚。

于 2013-01-05T14:52:04.117 回答
4

另一种可能性是在 R 包安装程序的右下角选择安装依赖项复选框:

在此处输入图像描述

于 2016-11-26T09:34:21.737 回答