gpt4 book ai didi

r - 可以声明包依赖项的显式版本吗?

转载 作者:行者123 更新时间:2023-12-04 11:40:59 24 4
gpt4 key购买 nike

对于我编写的代码,我倾向于明确而不是隐含。因此,在设法创建自己的包之后,我立即想到的下一件事是如何最好地确保我的代码的健壮性和可靠性。其中一部分与我的包所依赖的包有关。

实际问题

在这方面:是否可以明确说明需要/需要哪个版本的包依赖项?

我正在寻找不需要说明实际路径的方法,例如 zip文件(当然这很容易实现),但只需使用 install.packages说明包名称的“标准行为”只有 (可能有一些所需版本的引用)。

尽职调查

我查过 Writing R Extensions看看我对 Depends 的选择是什么DESCRIPTION的部分文件,希望有一个类似的机制来说明所需的 R 版本(例如 R (>= 2.15.2))。但我没有发现任何类似的包依赖项:

The ‘Depends’ field gives a comma-separated list of package names which this package depends on. The package name may be optionally followed by a comment in parentheses. The comment should contain a comparison operator, whitespace and a valid version number.

You can also use the special package name ‘R’ if your package depends on a certain version of R — e.g., if the package works only with R version 2.11.0 or later, include ‘R (>= 2.11.0)’ in the ‘Depends’ field. You can also require a certain SVN revision for R-devel or R-patched, e.g. ‘R (>= 2.14.0), R (>= r56550)’ requires a version later than R-devel of late July 2011 (including released versions of 2.14.0). Both library and the R package checking facilities use this field: hence it is an error to use improper syntax or misuse the ‘Depends’ field for comments on other software that might be needed. Other dependencies (external to the R system) should be listed in the ‘SystemRequirements’ field, possibly amplified in a separate README file.

The R INSTALL facilities check if the version of R used is recent enough for the package being installed, and the list of packages which is specified will be attached (after checking version requirements) before the current package, both when library is called and when preparing for lazy-loading during installation.



然后我也看了个 install.packages并希望像 version 这样的东西争论,但我想没有。

免责声明

我非常清楚我的问题的目标可能与 R 通过 CRAN 包存储库分发和安装包的理念形成对比,其中(至少我猜)某些包的新版本只是“覆盖”以前的版本和 install.packages()总是选择最新的可用。对最终用户隐藏版本特性也很有意义,以免使事情变得过于复杂。

然而,关于编写尽可能健壮的代码的目标,恕我直言,非常明确地陈述事情也是有意义的。或者至少可以选择这样做。

最佳答案

您确实使用了 Depends .例如:

Depends: R (>= 2.15.0), foo (== 1.17-12)

将依赖大于或等于 2.15.0 的 R 版本和 包装上 foo等于 1.17-12 .

(至少如果我理解正确的话,您想明确说明您的包仅适用于版本 x.yy-zz 的包 foo 。)

不过,我不确定这对最终用户有多大帮助;您可能会强制他们维护单独的软件包库,以便使用您的软件包来维护您规定的确切版本。

关于r - 可以声明包依赖项的显式版本吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13267140/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com