0

I am confused about something. when I put this function into a package

oddTranspose <- function(x) {
  t(x)
}

it works fine

m <- matrix(c(1,0,0,0), nrow=2)
M <- as(m, "Matrix")

oddTranspose(m) # works
oddTranspose(M) # works

but then, when I use devtools::test(), it stops working

devtools::test()
oddTranspose(m) # works
oddTranspose(M)
## t.default(x) : argument is not a matrix

This is problematic for me because I test my packages with the following work flow:

build the package, putting a file called

package_root\tests\testthat_tests.R, with the body

require(testthat)
require(myPackage)
test_check('myPackage')

and then in

package_root\tests\testthat\file.R, I put tests

I then test them in R with

library(testthat)
setwd("package_root/tests")
devtools::test()

what can I do?

Note that I spared you all of the text of my package overhead but the package's NAMESPACE imports the Matrix package and exports oddTranspose, and that the package DESCRIPTION "depends" on Matrix.

4

1 回答 1

0

解决此问题的方法是(1)将所有 setGeneric 调用移至 all.R(或提前加载 .R 文件)和(2)将所有 setMethod 调用移至函数所在的文件内部。

于 2016-02-27T04:54:53.910 回答