For information on using this system, please visit this page.
On the R version 3.3.1 when making a new class that contains a factor as the S3 part of the class it looks like the new class does not inherit behavior expected from a class that is based on a factor type. > setClass('newFactor', representation = c(tempValue='character'), contains = > 'factor') > ttt<-new('newFactor',tempValue='ddd') > S3Part(ttt)<-factor(c('a','b','c')) > table(S3Part(ttt)) a b c 1 1 1 > table(ttt) Error in as.character.factor(x) : attempting to coerce non-factor >
BTW: the same code run with no errors on older version of R (3.2.?) and produce the expected results.
Could fix this by having the check use inherits3(), but the broader issue is that C-level inherits() is basically broken for S4 objects and has other inconsistencies with R-level inherits(). It's used all over the place. It could be made smarter, but since it's in Rinlinedfuncs.h, it does not have access to e.g. R_data_class(). Does it really have to be inlined?
(In reply to Michael Lawrence from comment #2) > Could fix this by having the check use inherits3(), but the broader issue is > that C-level inherits() is basically broken for S4 objects and has other > inconsistencies with R-level inherits(). It's used all over the place. It > could be made smarter, but since it's in Rinlinedfuncs.h, it does not have > access to e.g. R_data_class(). Does it really have to be inlined? I have ~10K lines of code with a very complex system so practically this change in the behavior of R not trivial to fix. The broader picture is that it breaks the entire concept of Object Oriented Programing (OOP). IfS4 class in R can contains (inherit) S3 object, for example: setClass('newFactor', representation = c(tempValue='character'), contains = 'factor') then the new class should contain the functionality of the inherited class 'factor', otherwise S4 classes should not be able to inherit (contain) S3 classes. I'm just trying to figure out my next steps and understand if/how this inconstancy with OOP consent will be resolved.
Just to clarify, that question was directed at others (in R core). This has exposed a fairly deep issue in R that should be discussed.
@Michael, Appreciate if you can provide a link to these discussions in R core, it will probably may be of interest for many users. Is there a way for me to join this group for further discussions? (In reply to Michael Lawrence from comment #4) > Just to clarify, that question was directed at others (in R core). This has > exposed a fairly deep issue in R that should be discussed.
Ideally that discussion would happen here, but it hasn't happened yet.
I've fixed this in devel for now by introducing C-level inherits2() that respects S4 inheritance (and implicit classes).