实际问题
似乎devtools::test()
不能确保在DESCRIPTION
运行单元测试之前加载包文件中所述的包依赖项。我该如何改变呢?
细节
我正在编写一个包 ( B
) 来导入我的另一个包 ( A
)。
当我尝试通过 运行单元测试devtools::test()
,或者更准确地说,通过 RStudio 中的快捷方式运行单元测试时,某些测试会失败,因为导入的包似乎被忽略/未加载,因此无法找到SHFT + CRTL + T
某个函数 ( )。isPackageInstalled
尝试在运行之前A
手动加载导入的包也无济于事。我想这是因为(或)“模拟”了一个新的工作空间状态?不过,在事先手动加载包之后,“一个接一个”地运行单元测试就可以了。devtools::test()
devtools
testthat
A
我认为 devtools 会在DESCRIPTION
文件中查找包依赖项B
,从而像运行时那样加载它们require("B")
,但显然不是。
这是我的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
窗格给我的:
==> 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
我在这里错过了什么吗?
构建工具对话截图: