I found a weird problem in testthat while working with an ALTREP package.
The package name is AltWrapper. My ALTREP serialize function is called even
when I'm trying to serialize a non-ALTREP object. Here is an example
There is nothing but two variables A and B in the test function. I use
browser() to stop and debug the code. Here is the weird thing, my package
function is called when I’m trying to serialize *A* and *B*:
Browse> A = 10
Browse> B = new.env()
Auto serializing data
 "Internal serialize altWrapper function"
The output indicates that my package function is called. The function is
designed for an ALTREP object. Since *B* is not an ALTREP, I don’t
understand why the ALTREP related function has been called. Also, variable
A works find. It seems like R dispatches the serialize function according
to the variable type, but I am not sure if there is any way to see the
dispatching rules. Here are the things I have tried:
1. if I comment out the code that defines an ALTREP in my example, the bug
will disappear, so it might relate to the implementation of ALTREP.
2. If I run the test script in the global environment, R wouldn’t call the
internal function, it only happens when I call `devtools::test()`.
I am stuck here. I do not know if it is a bug of my package or testthat or
the ALTREP implementation of R or possibly the interaction between them. I
will appreciate if anyone can shed light on it. Here is the link to my
package test file:
On 12 August 2019 at 12:56, Wang Jiefei wrote:
| I am stuck here. I do not know if it is a bug of my package or testthat or
| the ALTREP implementation of R or possibly the interaction between them.
I don't have any concrete advice for your issue here but when I find myself
in similar debugging situations involving four or more moving parts, I
usually try to remove one or two. Once I am down to 'just base R and my
package' it tends to become much clearer where the issue is.