如何使devtools :: test()考虑包依赖关系 [英] How to make devtools::test() consider package dependencies

查看:155
本文介绍了如何使devtools :: test()考虑包依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎像devtools::test()一样,不能确保在运行单元测试之前已加载包DESCRIPTION文件中所述的包依赖关系.我该如何更改?

Seems like devtools::test() does not make sure that package dependencies as stated in a package's DESCRIPTION file are loaded prior to running the unit tests. How can I change that?

我正在编写一个程序包(B),该程序包将导入我的另一个程序包(A).

I'm writing a package (B) that imports another one of my packages (A).

当我尝试通过devtools::test()或者更确切地说通过RStudio中的快捷方式SHFT + CRTL + T运行单元测试时,某些测试失败,因为导入的软件包似乎被忽略/未加载,因此具有某些功能(isPackageInstalled)找不到.

When I try to run my unit tests via devtools::test(), or, to be more precise via the shortcut SHFT + CRTL + T in RStudio, certain tests fail as the imported package seems to be disregarded/not loaded and thus a certain function (isPackageInstalled) can't be found.

在运行devtools::test()之前 尝试手动加载导入的软件包A也无济于事.我想这是由于devtools(或testthat)模拟"了新的工作区状态的缘故?但是,在事先手动加载软件包A之后,一个一个地"运行单元测试就可以了.

Trying to load the imported package A manually before running devtools::test() didn't help either. I guess that's due to the fact that devtools (or testthat) "simulates" a fresh workspace state? Running the unit tests "one by one" works just fine after manually loading package A beforehand, though.

我认为devtools会在BDESCRIPTION文件中查找程序包依赖项,从而像运行require("B")时那样加载它们,但显然不是.

I thought that devtools would look up package dependencies in the DESCRIPTION file of B and thus load them as would be the case when running require("B"), but apparently not.

这是我的DESCRIPTION文件:

Package: B
Type: Package
Title: What the package does (short line)
Version: 0.1.0.1
Date: 2014-08-05
Author: Who wrote it
Maintainer: Who to complain to <yourfault@somewhere.net>
Description: More about what it does (maybe more than one line)
License: What license is it under?
Imports: A

这是我运行的代码:

devtools::load_all()  # or SHFT + CTRL + L in RStudio
devtools::test()      # or SHFT + CTRL + T in RStudio

这就是RStudio的build窗格给我的:

That's what RStudio's build pane gave me:

==> devtools::test()

Loading required package: testthat
Testing B
Loading B
Creating a new generic function for 'signalCondition' in package 'B'
package : 1
package : ......


1. Error: getPackageDescription ------------------------------------------------
could not find function "isPackageInstalled"
1: expect_is(res <- getPackageDescription(), expected) at test-getPackageDescription.r:13
2: expect_that(object, is_a(class), info, label)
3: condition(object)
4: paste0(class(x), collapse = ", ")
5: getPackageDescription()
6: getPackageDescription() at Q:\home\wsp\rapp2\B/R/getPackageDescription.r:37
7: getPackageDescription(from = from, fields = fields, drop = drop, encoding = encoding, 
       ...) at Q:\home\wsp\rapp2\B/R/getPackageDescription.r:154
8: getPackageDescription(from = from, fields = fields, drop = drop, encoding = encoding, 
       ...) at Q:\home\wsp\rapp2\B/R/getPackageDescription.r:37

我在这里想念东西吗?

构建工具对话框的屏幕截图:

Screenshot of build tools dialogue:

推荐答案

通常的方法是使用roxygen2通过源代码中的特殊注释自动生成NAMESPACE文件,但维护您的DESCRIPTION文件手动.我知道没有什么特别的东西可以使它们保持同步,但是R CMD CHECK会告诉您DESCRIPTION中是否缺少/多余的东西.

The usual approach would be to use roxygen2 to automatically generate your NAMESPACE file from special comments in your source code, but maintain your DESCRIPTION file manually. There's no special stuff that I'm aware of to keep them in sync, but R CMD CHECK will tell you if there's something missing/extra in your DESCRIPTION.

这篇关于如何使devtools :: test()考虑包依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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