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

Sort out S3 and S4 method dispatch for standard generics #32

Open
13 tasks
pschil opened this issue Mar 26, 2020 · 3 comments
Open
13 tasks

Sort out S3 and S4 method dispatch for standard generics #32

pschil opened this issue Mar 26, 2020 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@pschil
Copy link
Collaborator

pschil commented Mar 26, 2020

Are S4 methods needed where only S3 methods exist?
Are S3 methods needed where only S4 methods exist?
Reference: https://stackoverflow.com/questions/32512785/properly-specify-s4-generics

  • plot (data, fitted)
  • predict
  • show
  • print
  • summary
  • coef
  • nobs
  • vcov
  • confint
  • logLik
  • fitted
  • pnbd
  • further model stubs
@pschil pschil self-assigned this Mar 26, 2020
@pschil pschil added this to the v0.5 milestone Mar 26, 2020
@mmeierer mmeierer added the enhancement New feature or request label Mar 26, 2020
@pschil
Copy link
Collaborator Author

pschil commented Mar 27, 2020

From ?Methods_for_S3:

"the recommended approach is to do both: register the S3 method and supply the identical function as the definition of the S4 method. This ensures that the proposed method will be dispatched for any applicable call to the function."

This requires, as per example in ?Methods_for_S3:
S3 method: method.class <- function()
S4 method: setMethod("method", "class", function())
And in the namespace file:
S3 method export: S3method(method, class)
S4 method export: exportMethod(method)

S3 methods, without S4 generic by default
As specifically recommended, these should receive a corresponding S4 method. There would be no need to define the S4 generic method itself (ie setGeneric(summary)) because setting "an S4 method, which will have the side effect of creating an S4 generic version of this function". However, explicit is better than implicit, therefore define S4 generics as well.

This includes:

  • predict
  • summary
  • print
  • plot
  • all from stats coef, vcov, nobs, etc

S4 methods, without S3 generic by default
S4 objects use show instead of print. Define the method for print forward from S4 show as implicitly recommended ("supply the identical function as the definition of the S4 method").

Exported CLVTools S4 methods
These should also define and receive corresponding S3 methods and implementations for all clv.data classes and a default with only stop().

This includes:

  • model interface methods: pnbd(), gnbd(), etc

@pschil
Copy link
Collaborator Author

pschil commented Mar 27, 2020

Also the documentation has to be adapted to account for the method effectively being present twice.

@pschil
Copy link
Collaborator Author

pschil commented Apr 29, 2020

As of now, exporting an S3 standard method as S4 generic leads to troubles with roxygen. It can apparently handle a function only as either S3 or S4 and otherwise exports them wrongly as non-generics. Because this feature is not really important, its put on hold.

@pschil pschil removed this from the v0.5 milestone May 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants