在 CRAN 包中包含非 CRAN 包 [英] Include non-CRAN package in CRAN package

查看:17
本文介绍了在 CRAN 包中包含非 CRAN 包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题很简单.第一:

  1. 是否可以在 CRAN 包中包含非 CRAN(或 bioconductor,或 omega hat)包,并在示例中实际使用该包中的工具.
  2. 如果是,如何设置 DESCRIPTION 文件等以使其合法并通过 CRAN 检查?

具体来说,我问的是曾经是 CRAN 包的 openNLPmodels.en.它非常有用,并且希望包含其中的功能.我可以做一个解决方法,而不是在示例中实际使用 openNLPmodels.en 或为其创建单元测试,并在使用函数时安装它(类似于 genderstrong> 包安装它需要的数据集),但我更喜欢一种允许我运行检查、文本、示例的方法.

这是下载和安装 openNLPmodels.en

的方式

install.packages("http://datacube.wu.ac.at/src/contrib/openNLPmodels.en_1.5-1.tar.gz",回购=空,类型=来源")

解决方案

现有答案很好,但没有详细解释整个过程,所以发布这个.


<块引用>

是否可以在 CRAN 包中包含非 CRAN(或 bioconductor,或 omega hat)包,并在示例中实际使用该包中的工具.

是的,这是可能的.此类非 CRAN 的任何使用(包代码、示例、测试、小插曲)都必须像 Suggests 中的任何其他包一样进行转义,最好使用

if (requireNamespace("non.cran.pkg", quiet=TRUE)) {non.cran.pkg::fun()} 别的 {cat(由于缺少建议的依赖项而跳过功能")}

<块引用>

如果是,如何设置DESCRIPTION文件等以使其合法并通过CRAN检查?

您需要使用DESCRIPTION文件中的Additional_repositories字段.该字段中提供的位置必须包含预期目录结构,适当目录中的 PACKAGES 文件,并且 PACKAGES 文件必须列出非 CRAN 包.


现在转到 openNLPmodels.en 包的特定示例.根据您下载和安装的方式,此软件包无法将其用作依赖项并传递给 CRAN.openNLPmodels.en 必须以 R 存储库预期的结构发布.否则,您没有有效的位置可放入 Additional_repositories 字段.

您可以做的是下载非 CRAN 包并将其发布到您自己的 R 存储库中,然后在您的 CRAN 包的 Additional_repositories 字段中使用该位置.这是一个如何做的例子:

dir.create("src/contrib", recursive=TRUE)下载.file("http://datacube.wu.ac.at/src/contrib/openNLPmodels.en_1.5-1.tar.gz", "src/contrib/openNLPmodels.en_1.5-1.tar.gz")工具::write_PACKAGES(src/contrib")

我们只是将包源放在预期的目录 src/contrib 中,其余的由 write_PACKAGES 函数很好地处理.为确保正确创建存储库,您可以列出该存储库中可用的包:

available.packages(repos=file.path("file:/",getwd()))

它应该在那里列出您的非 CRAN 包.然后在 R 存储库中发布非 CRAN 包,您应该将存储库的位置放入 CRAN 包的 Additional_repositories 字段中.在这种情况下,位置将是 file.path("file:/",getwd()) 表达式返回的位置.

请注意,它使用本地计算机上的位置,您可能希望将其放到网上,以便任何检查您的 CRAN 包的机器都可以访问该 URL,包括对 CRAN 本身的检查.为此,只需将您的 src 目录移动到将在网上某处托管的 public 目录并使用该服务器的位置.


现在再次查看您的非 CRAN 包,我们可以看到它的 url 中有 src/contrib,因此我们可以假设它已经存在适当的 R 存储库而我们没有创建和发布新的.因此,您的安装说明可能如下所示

install.packages(openNLPmodels.en",repos=http://datacube.wu.ac.at",类型=来源";)

然后,您的 CRAN 包所需要做的就是使用可用的现有存储库

Additional_repositories http://datacube.wu.ac.at

The question is pretty simple. First:

  1. Is it possible to include a non-CRAN (or bioconductor, or omega hat) package in a CRAN package and actually use tools from that package in examples.
  2. If yes how does one set up the DESCRIPTION file etc. to make it legit and pass CRAN checks?

Specifically I'm asking about openNLPmodels.en that used to be a CRAN package. It's pretty useful and want to include functionality from it. I could do a work around and not actual use openNLPmodels.en in the examples or create unit tests for it, and have it install when a function gets use (similar to how the gender package installs the data sets it needs) but I'd prefer an approach that allows me to run checks, texts, examples.

This is how one downloads and installs openNLPmodels.en

install.packages(
    "http://datacube.wu.ac.at/src/contrib/openNLPmodels.en_1.5-1.tar.gz",  
    repos=NULL, 
    type="source"
)

解决方案

Existing answer is good but doesn't explain the whole process fully in details so posting this one.


Is it possible to include a non-CRAN (or bioconductor, or omega hat) package in a CRAN package and actually use tools from that package in examples.

Yes, it is possible. Any use (package code, examples, tests, vignettes) of such non-CRAN has to be escaped as any other package in Suggests, ideally using

if (requireNamespace("non.cran.pkg", quietly=TRUE)) {
  non.cran.pkg::fun()
} else {
  cat("skipping functionality due to missing Suggested dependency")
}

If yes how does one set up the DESCRIPTION file etc. to make it legit and pass CRAN checks?

You need to use Additional_repositories field in DESCRIPTION file. Location provided in that field has to contain expect directory structure, PACKAGES file in appropriate directory, and PACKAGES file has to have non-CRAN package listed.


Now going to your particular example of openNLPmodels.en package. According to the way how you download and install this package it will not be possible to use it as dependency and pass on CRAN. openNLPmodels.en has to be published in a structure expected from R repository. Otherwise you don't have a valid location to put into Additional_repositories field.

What you can do is to download non-CRAN package and publish it in your R repository yourself, and then use that location in Additional_repositories field in your CRAN package. Here is an example of how to do it:

dir.create("src/contrib", recursive=TRUE)
download.file("http://datacube.wu.ac.at/src/contrib/openNLPmodels.en_1.5-1.tar.gz", "src/contrib/openNLPmodels.en_1.5-1.tar.gz")
tools::write_PACKAGES("src/contrib")

We just put package sources in expected directory src/contrib and the rest is nicely handled by write_PACKAGES function. To ensure that repository is properly created you can list packages that are available in that repository:

available.packages(repos=file.path("file:/",getwd()))

It should list your non-CRAN package there. Then having non-CRAN package published in R repository you should location of the repository into Additional_repositories field of your CRAN package. In this case location will be location returned by file.path("file:/",getwd()) expression.

Note that it uses location on your local machine, you will probably want to put it online, so that url can accessed by any machine checking your CRAN package, including checks on CRAN itself. For that just move your src directory to a public directory that is going to be hosted somewhere online and use the location of that server.


Now looking at your non-CRAN package again, we can see it has src/contrib in its url, thus we can assume that proper R repository already exists for it and we don't have to create and publish new one. Therefore your installation instruction could look like

install.packages(
  "openNLPmodels.en", 
  repos="http://datacube.wu.ac.at",
  type="source"
)

And then all you need for your CRAN package is to use existing repository where it is available

Additional_repositories http://datacube.wu.ac.at

这篇关于在 CRAN 包中包含非 CRAN 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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