Hi
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 ``` context("altrep") length_func<-function(x){ return(length(x)) } setAltClass(className = "test", classType = "real") setAltMethod(className = "test", getLength = length_func) testData = runif(10) myAltrep = makeAltrep("test", testData) test_that("Auto serialize", { browser() A = 10 A_serialized=serialize(A,NULL) B = new.env() B_serialized=serialize(B,NULL) }) ``` 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[1]> A = 10 Browse[1]> A_serialized=serialize(A,NULL) Browse[1]> B = new.env() Browse[1]> B_serialized=serialize(B,NULL) serializing data Auto serializing data [1] "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: https://github.com/Jiefei-Wang/AltWrapper/blob/master/tests/testthat/test_test.R Best, Jiefei [[alternative HTML version deleted]] ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel