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

Delayed registration? #5

Closed
hadley opened this issue May 11, 2020 · 5 comments · Fixed by #14
Closed

Delayed registration? #5

hadley opened this issue May 11, 2020 · 5 comments · Fixed by #14

Comments

@hadley
Copy link
Member

hadley commented May 11, 2020

Should we explicitly consider delayed registration in the requirements? This is needed if you want to provide a method for a generic (or class) that is available in a suggested (not imported) package.

R-exsts has:

As from R 3.6.0 one can also use S3method() directives to perform delayed registration. With

if(getRversion() >= "3.6.0") {
   S3method(pkg::gen, cls)
}
@lawremi
Copy link
Collaborator

lawremi commented May 12, 2020

Yes, this would be useful. Taking the object-oriented approach, we could have a proxy object representing the generic/class. It would react to the loading of the actual definition. Perhaps constructed like:

MyClass <- make_class(pkg::SuperClass, ...)

Just as with S3method(), it would see the namespace qualifier and default to laziness.

@hadley
Copy link
Member Author

hadley commented May 13, 2020

I just remembered there's another case where you need condition method registration — when you're releasing a package that works with multiple versions of a dependency.

For example, dplyr 1.0.0 added a new generic dplyr_reconstruct(). If your pacakge extends dplyr, you'd like to be able to release a new version that works with both dplyr 0.8.5 and dplyr 1.0.0, before dplyr 1.0.0 is released. That means you want to register the method only if dplyr 1.0.0 or later is available when your package is loaded.

@lawremi
Copy link
Collaborator

lawremi commented May 13, 2020

That may be the only practical solution; however, it would obviously be ideal if you could test against a branch of the dependency and then coordinate the release.

Anyway, since registration would happen in regular R code, it could operate conditionally, although if we're doing any caching it could get messy.

@hadley
Copy link
Member Author

hadley commented May 13, 2020

That also forces the users of the package to update to the latest version of its dependency; that's not always great if it's mostly a data-analyst facing package.

hadley added a commit that referenced this issue Jul 20, 2020
@mmaechler
Copy link
Collaborator

I just remembered there's another case where you need condition method registration — when you're releasing a package that works with multiple versions of a dependency.

For example, dplyr 1.0.0 added a new generic dplyr_reconstruct(). If your pacakge extends dplyr, you'd like to be able to release a new version that works with both dplyr 0.8.5 and dplyr 1.0.0, before dplyr 1.0.0 is released. That means you want to register the method only if dplyr 1.0.0 or later is available when your package is loaded.

I vaguely remember this almost works now already in NAMESPACE, as it allows conditionals; however that of course maybe at the wrong point in time: The (non-)registration should happen at package load time, not at build time.

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

Successfully merging a pull request may close this issue.

3 participants