-
Notifications
You must be signed in to change notification settings - Fork 32
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
class_null #337
Comments
(ok, not per se, 'cuz you can't inherit from it... but guidance for how to dispatch for it would be helpful!) |
You can just use a literal library(S7)
g <- new_generic("g", "x")
method(g, NULL) <- function(x) "hello"
g(NULL)
#> [1] "hello" Created on 2023-09-08 with reprex v2.0.2 This presumably should be documented somewhere. |
I could have sworn that didn't work! I wonder what I did. Thanks for the tip! 🙃 |
Aha! This is (equivalent to) what I tried that failed: library(S7)
g <- new_generic("g", "x")
method(g, class_missing | NULL) <- function(x) "hello"
#> Error in class_missing | NULL: operations are possible only for numeric, logical or complex types
g(NULL)
#> Error: Can't find method for `g(<NULL>)`. Created on 2023-09-08 with reprex v2.0.2 vs library(S7)
g <- new_generic("g", "x")
method(g, class_missing | new_S3_class("NULL")) <- function(x) "hello"
g(NULL)
#> [1] "hello" Created on 2023-09-08 with reprex v2.0.2 I'm going with the separate method for |
Ah that I can fix. |
For method dispatch,
class_missing
doesn't catchNULL
(which it shouldn't, really). This works, but it doesn't feel quite right:class_null <- S7::new_S3_class("NULL")
. Shouldclass_null
be in the base types?The text was updated successfully, but these errors were encountered: