-
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
How to define S3 / S7 methods on namespaced classes #333
Comments
That really should not happen. As you have attached BTW, I think we have a missing feature in S7 also: I did not find (in S7) utility functions listing Back to your problem "doctor, it hurts if I do this ..... then, don't do that!" |
Agreed.
Yes, this would certainly be helpful.
That would simplify the client package story a bit, if the back-end can still keep track of everything. |
@jonclayden do you have a simple package reprex somewhere? |
Now created: remotes::install_github("jonclayden/S7issue333")
library(S7issue333)
a <- myarray(data=1:4, dims=c(2L,2L))
dim(a)
## NULL
class(a)
## [1] "S7issue333::myarray" "S7_object" |
@mmaechler we currently have an explicit class argument because it's useful for testing and sometimes you need to move classes from one package to another while preserving the original package name. I'm not sure we ever discussed how to do that automatically. I'm pretty sure we did discuss that the easiest approach for package namespace using S3 classes was to include the package name in the class name; anything else would break S7/S3 compatibility in a way that we didn't want. |
Hmmm, looks like you don't even need to be in a package for this to be a problem: library(S7)
myarray <- new_class("myarray", package = "foo")
method(dim, myarray) <- function (x) 1
dim(myarray())
#> NULL Created on 2023-09-08 with reprex v2.0.2 |
No, indeed – the example in the first comment runs as-is, if you drop the |
I'm kicking the tyres on the
S7
project by trying to create a fork of one of my packages that uses it (instead of reference classes). One thing I've got stuck on so far is defining methods for package-namespaced classes.The documentation recommends specifying the package, viz.
But now, when I try to define a simple S3 method like
it doesn't seem to be picked up:
I am calling
S7::methods_register()
in.onLoad()
and exporting themyarray
constructor.The issue appears to be that the class of
a
is nowmypackage::myarray
, which doesn't match the method so it isn't used. But scoping the class in the call tomethod<-
doesn't work either. If I remove thepackage="mypackage"
bit then everything works.I'm not sure if I've missed the correct incantation from the documentation, or this a bug, but any pointers would be appreciated. Thanks!
The text was updated successfully, but these errors were encountered: