Open rogerswt opened 9 years ago
@rogerswt Thank you very much for this reproducible example. Issue CCT-70 raised.
BTW, should have mentioned: R: 3.1.0 (linux x86_64 kernel 2.6.18-274.3.1.el5.centos.plus) testthat: 0.9.1 testCoverage: 0.1.02 flowCore: 1.30.7
W>
Another quick update. I found that testCoverage works fine for another bioconductor package object, a flowFP object from package flowFP.
I made and saved a flowFP object called 'fp'. Added a function to coverage_func.R thus:
myfunc.fp = function (x) {
require ("flowFP")
cmat = counts(fp)
cmat
}
Added a test to testthat_coverage_func.R, and commented out the flowFrame one that failed:
#
# testthat toy test script.
# Looking for an issue with flowCore::flowFrame
#
# 2014-12-10 WTR
#
library("flowCore")
library("testthat")
context ("TestCoverage")
load ("./testmat.rda") # instantiates a matrix called 'mat'
load ("./fp.rda") # instantiates a flowFP object called 'fp'
test_that ("test.myfunc.mat", {
expect_equal (nrow(mat), 4)
expect_equal (ncol(mat), 2)
expect_equal (colnames(mat), c("FSC-A", "SSC-A"))
expect_equal (myfunc.mat(mat), 8)
})
# test_that ("test.myfunc.ff", {
# ff = new("flowFrame", exprs=mat)
# expect_equal (nrow(ff), 4)
# expect_equal (colnames(ff), c("FSC-A", "SSC-A"))
# })
test_that ("test.myfunc.fp", {
expect_equal (ncol(myfunc.fp(fp)), 256)
})
Ran testthat:
> test_file ("testthat_coverage_func.R")
TestCoverage : .....
Ok. Then ran reportCoverage:
> reportCoverage (sourcefiles="coverage_func.R", executionfiles="testthat_coverage_func.R", writereport=T)
1 coverage_func.R ... replacing 26 symbols... setting 6 trace points...
Evaluating instrumented code from coverage_func.R in Global Env
removing 3 trace points for assigning...
1 : reading testthat_coverage_func.R ...OK.
Output to /home/rogers/git/R/tools/testdata/coverage_report.html
$A
coverage_func.R
Trace Points 13
testthat_coverage_func.R 7
$E
[1] FALSE
$B
$B$testthat_coverage_func.R
coverage_func.R
Executed 7
Not Executed 6
which seems to have worked just fine. So the problem so far seems restricted to the flowFrame object.
Cheers, Wade
First, many thanks for testCoverage. It's the cat's meow!
I'm a heavy user/developer of R for flow cytometry. Most of my code depends on the bioconductor library flowCore. The basic object in flowCore is a
flowFrame
. I've written testthat tests which run fine, butreportCoverage
fails. I suspect it has something to do with the way testCoverage manipulates environments, but I have no real understanding of this.I've boiled the problem down to something I hope you'll be able to easily reproduce. Here is the code I want to test and analyze for coverage:
There are two nearly identical functions. One takes a
matrix
as it's sole argument, the other takes aflowFrame
.Here's a testthat test file (which I named
testthat_coverage_func.R
):Notice that the test for the flowFrame version constructs a new flowFrame from mat, so it's exactly the same data, but stored in a different c4 object.
The rda file was created thus:
It runs perfectly fine in testthat:
So far, so good. Here's the problem. We load the testCoverage library, the execute the coverage test:
Notice that colnames(ff) is NULL. This is the problem. In the context of testCoverage, we seem to be unsuccessful in handling flowFrame objects.
I hope this gives you a useful test case. Please let me know if I can help further in any way.
Again, thanks for this very important contribution to the field!
All the best, Wade