Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S4 ambiguous method #1742

Open
CrossD opened this issue Sep 22, 2022 · 0 comments
Open

S4 ambiguous method #1742

CrossD opened this issue Sep 22, 2022 · 0 comments

Comments

@CrossD
Copy link

CrossD commented Sep 22, 2022

When an S4 class has two (immediate) parent classes, the two classes are regarded as ordered, and the distance to the first class is shorter than to the 2nd class. Thus, the way S4 disambiguous method is not entirely like described in Ch 15. The second figure regards the superclasses as un-ordered, which is what current implementation (I am on R 4.2.1) reflects:

> setClass("A", slots=c(a  = "numeric"))
> setClass("B", slots=c(b  = "numeric"))
> setClass("AB", contains=c("A", "B"))
> setGeneric("myg", function(object) standardGeneric("myg"))
[1] "myg"
> 
> setMethod("myg", "A", function(object) 1)
> setMethod("myg", "B", function(object) 2)
> ab <- new("AB", a=1, b=2)
> myg(ab) # No warning of ambiguity
[1] 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant