可以声明软件包依赖关系的显式版本吗? [英] Possible to state explicit versions of package dependencies?

查看:173
本文介绍了可以声明软件包依赖关系的显式版本吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我编写的代码,我倾向于露骨而不是隐含.因此,在设法创建了自己的程序包之后,我立即想到的第二件事是如何最好地确保代码的健壮性和可靠性.部分原因与我的软件包所依赖的软件包有关.

实际问题

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

我正在寻找不需要说明例如zip文件的实际路径(当然很容易实现)的方法,而只是利用install.packages的标准行为"说明软件包名称,仅(可能带有所需版本的一些参考).

应有尽责

我已检查编写R扩展来查看关于DESCRIPTION文件的Depends部分的选择,希望能找到一种类似的机制来说明所需的R版本(例如R (>= 2.15.2)).但是我没有发现任何类似的软件包依赖项:

依赖"字段提供了一个逗号分隔的软件包名称列表,该软件包所依赖的软件包名称.软件包名称后可以选择用括号括起来.注释应包含比较运算符,空格和有效的版本号.

如果您的软件包依赖于特定版本的R,也可以使用特殊的软件包名称'R'-例如,如果该软件包仅适用于R版本2.11.0或更高版本,则包含'R(> = 2.11.0 )"中的依赖"字段.对于R-devel或R-patched,您还可能需要特定的SVN版本,例如"R(> = 2.14.0),R(> = r56550)"要求的版本晚于2011年7月下旬的R-devel(包括2.14.0的发行版本).库和R软件包检查工具都使用此字段:因此,使用不正确的语法或将"Depends"字段误用于可能需要的其他软件的注释是错误的.其他依赖项(R系统外部)应在"SystemRequirements"字段中列出,并可能在单独的README文件中进行放大.

R INSTALL设施检查所用R的版本是否足够接近所安装的软件包,并且在调用库时都会在当前软件包之前附加指定的软件包列表(在检查版本要求之后).以及在安装过程中准备延迟加载时.

然后我也看了install.packages并希望有类似version的参数,但我想没有.

免责声明

我完全意识到问题的目的可能与R的通过CRAN软件包存储库分发和安装软件包的哲学形成对比,在CRAN软件包存储库中(至少我猜)某些软件包的新版本只是推翻"先前的软件包,而install.packages()总是挑选最新的可用.隐藏最终用户的版本特性也很有意义,以免使事情变得过于复杂.

但是,关于编写尽可能健壮的代码的目标,恕我直言,非常明确地声明事物也是有意义的.或至少可以选择这样做.

解决方案

您确实使用了Depends.例如:

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

将依赖于大于或等于2.15.0 的R版本,并且对foo等于1.17-12的软件包的依赖.

(至少,如果我对您的理解正确,您要明确声明您的软件包仅在软件包 foo 的版本x.yy-zz只能使用.)

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

I tend to be rather explicit than implicit about the code I write. So after having managed to create my own packages, the next thing that immediately comes to my mind is how best to ensure robustness and reliability of my code. Part of that has to do with the packages my package depends on.

Actual Question

In that respect: is it possible to explicitly state which version of a package dependency is required/desired?

I'm looking for ways that don't require stating the actual path to, say, the zip file (which of course would easily be possible), but just make use of install.packages "standard behavior" of stating the package name only (possibly with some reference of the required version).

Due dilligence

I've checked Writing R Extensions to see what my options are with respect to the Depends section of the DESCRIPTION file, hoping for a similar mechanism that works for stating the required R version (e.g. R (>= 2.15.2)). But I didn't find anything similar for package dependencies:

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.

Then I also had a look a install.packages and hoped for something like a version argument, but I guess there isn't.

Disclaimer

I'm perfectly aware that the goal of my questions might contrast R's philosophy of distributing and installing packages via CRAN package repositories where (at least I guess) new versions of certain packages just "overrule" previous ones and install.packages() always picks up the latest one available. It also does make a lot of sense to hide version peculiarities from the end user in order not to make things overly complex.

Yet, with respect to the goal of writing as robust code as possible, IMHO it also makes sense to state things very explicitly. Or at least to have the option to do so.

解决方案

You do use Depends. For example:

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

would place a dependency on R versions greater than or equal to 2.15.0 and on package foo being equal to 1.17-12.

(At least if I have understood you correctly, that you want to state explicitly that your package works only with version x.yy-zz of package foo.)

I'm not sure how helpful this will be for end users though; you are probably going to be forcing them to maintain separate libraries of packages in order to use your package just to maintain the exact versions you stipulate.

这篇关于可以声明软件包依赖关系的显式版本吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆