Possible bug in `class<-` when a class-specific '[[.' method is defined
I'm unable to reproduce this with R 3.6.1. Which version are you using? Is this a fresh session?
On Mon, Jul 15, 2019 at 3:25 AM Ghiggi Gionata <gionata.ghiggi at epfl.ch> wrote:
Hi all !
I noticed a strange behaviour of the function `class<-` when a class-specific '[[.' method is defined.
Here below a reproducible example :
#-------------------------------------------------------------------.
counttt <- 0
`[[.MYCLASS` = function(x, ...) {
counttt <<- counttt + 1
# browser()
x = NextMethod()
return(x)
}
df <- as.data.frame(matrix(1:20, nrow=5))
class(df) <- c("MYCLASS","data.frame")
counttt
# The same occurs when using structure(, class=) or attr(,"class")<-
df <- as.data.frame(matrix(1:20, nrow=5))
df <- structure(df, class=c("MYCLASS","data.frame"))
attr(df, "class") <- c("MYCLASS","data.frame")
#-------------------------------------------------------------------.
Why in this example `class<-` is calling `[[.MYCLASS` 9 times ?
Is there a way to avoid `class<-` to call `[[.MYCLASS` ?
Thank you in advance for your help and suggestions.
Gionata
[[alternative HTML version deleted]]
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Michael Lawrence Scientist, Bioinformatics and Computational Biology Genentech, A Member of the Roche Group Office +1 (650) 225-7760 michafla at gene.com Join Genentech on LinkedIn | Twitter | Facebook | Instagram | YouTube