【问题标题】:Create an R package that includes a locally stored dependency创建一个包含本地存储依赖项的 R 包
【发布时间】:2022-01-12 22:50:01
【问题描述】:

我正在开发一个使用本地存储包的依赖项的 R 包,但我无法弄清楚如何在 DESCRIPTION 文件中正确列出该包。我正在构建的包是 PackageA,它依赖于 PackageB。在我从同事那里共享了 PackageB 的 zip 文件夹后,PackageB 本地存储在我的驱动器上。这两个软件包仅供内部使用,不会存储在任何存储库中。我发现以下页面显示了如何使用DESCRIPTION 文件中的Remotes: 标记来完成此操作:

https://cran.r-project.org/web/packages/devtools/vignettes/dependencies.html

这可以用下面的代码来完成,但是当我尝试这个时,我收到一个错误,如下所示:

#Example from linked vignette
# Local
Remotes: local::/pkgs/testthat

#Both of these attempts produce the same error
#1. Specify file path to the unpacked version of the package in my R library
Remotes: local::C:/Users/name/library/PackageB

#2. Specify file path to the original .zip version of the package
Remotes: local::C:/Users/name/library/PackageB.zip

#devtools::build() error
   ERROR: package installation failed
Error in (function (command = NULL, args = character(), error_on_status = TRUE,  : 
  System command 'Rcmd.exe' failed, exit status: 1, stdout + stderr:
E> * checking for file 'C:\Users\name\PackageA/DESCRIPTION' ... OK
E> * preparing 'PackageA':
E> * checking DESCRIPTION meta-information ... OK
E> * installing the package to build vignettes
E>       -----------------------------------
E> ERROR: dependency 'PackageB' is not available for package 'PackageA'
E> * removing 'C:/Users/tmpfolder/PackageA'
E>       -----------------------------------
E> ERROR: package installation failed

#Rstudio Install and Restart error; I would build the source after this but it doesn't get that far
Error: Dependency package(s) 'PackageB' not available.
Backtrace:
    x
 1. +-base::suppressPackageStartupMessages(...)
 2. | \-base::withCallingHandlers(expr, packageStartupMessage = function(c) tryInvokeRestart("muffleMessage"))
 3. \-devtools::document(...)
 4.   \-roxygen2::roxygenise(pkg$path, roclets)
 5.     \-roxygen2:::load_code(base_path)
 6.       \-pkgload::load_all(path, helpers = FALSE, attach_testthat = FALSE)
 7.         \-pkgload:::load_imports(path)
 8.           \-pkgload:::abort_for_missing_packages(res, imports$package)
Warning message:
In (function (dep_name, dep_ver = "*")  :
  Dependency package 'PackageB' not available.
Execution halted

Exited with status 1.

我想知道我是否错误地指定了文件路径,但也许它更复杂。

【问题讨论】:

    标签: r package devtools roxygen2


    【解决方案1】:

    “你不能”通过标准 repo 因为Imports 等需要访问包。您可以做的是创建一个本地存储库(例如,drat 软件包使这很容易),并将该存储库设置为测试框上的一组已知存储库(添加到 options(repos),或使用 drat 助手函数)然后进行测试。

    或者,您可以使用Additional_repositories 字段但仅用于建议:因此您必须在使用第一个包中的第二个包中的代码之前测试是否存在。

    而且,简而言之,“仅安装软件包”对于测试来说还不够好。只是不是 R 对包的看法。

    【讨论】:

    • 我已经开始关注这里的 drat 小插图:cran.r-project.org/web/packages/drat/vignettes/…。我成功创建了 repo 并添加了 PackageB。但是,当我尝试使用 install.packages 从 repo 测试安装时,我收到以下错误:Warning in install.packages : cannot open compressed file '/C:/Users/name/Documents/repo/src/contrib/PACKAGES', probable reason 'Invalid argument' Error in install.packages : cannot open the connection。我检查了 PACKAGES zip 文件夹,它说里面的文件没有扩展名。
    • 您创建的drat 存储库中有文件src/contrib/PACKAGES 吗?你有压缩版PACKAGES.gz吗?它是否包含您注入该存储库的包?您能否将 R 指向该存储库并通过 available.packages() 查询它是否可见?
    • PACKAGESPACKAGES.gz 都可用,尽管看起来它把它们放在 src/contrib/4.0 而不是 src/contrib 中。 available.packages() 返回一个关于无法打开 PACKAGES 的类似错误。我将src/contrib/4.0 的内容复制到src/contrib,但它返回相同的错误。目录的 4.0 部分是在运行 insertPackage 时创建的。
    • 注意sourcebinary包的区别。
    猜你喜欢
    • 1970-01-01
    • 2011-02-23
    • 2015-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-24
    • 2016-09-13
    • 1970-01-01
    相关资源
    最近更新 更多