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 class-based extension mechanism #256

Open
gustavdelius opened this issue Nov 2, 2022 · 2 comments
Open

S4 class-based extension mechanism #256

gustavdelius opened this issue Nov 2, 2022 · 2 comments
Labels
core Issue relates to the mizer core enhancement New feature requests or suggestions for enhancement of existing features
Milestone

Comments

@gustavdelius
Copy link
Member

Make functions that extension packages may want to change into methods. This includes all functions whose first argument is either a MizerParams or a MizerSim object. Extension packages would then create subclasses of these classes to dispatch their own methods.

@gustavdelius gustavdelius modified the milestones: Version 2.4, Version 3.0 Nov 2, 2022
@gustavdelius gustavdelius added enhancement New feature requests or suggestions for enhancement of existing features core Issue relates to the mizer core labels Nov 3, 2022
@gustavdelius
Copy link
Member Author

I am not yet sure whether we want to use S4 or S3. Even though MizerParams and MizerSim are S4 classes, we can still dispatch via the S3 mechanism, as the following demonstrates:

library(mizer)

setGeneric("test", function(params) standardGeneric("test"))

setMethod("test", "MizerParams", function(params) {
    params@initial_n[1, 1]
})

test(NS_params)

setClass("testParams",
         contains = "MizerParams")

setTest <- function(params) {
    as(params, "testParams")
}

NS_params_test <- setTest(NS_params)

setMethod("test", "testParams", function(params) {
    summary(params)
})

test(NS_params_test)

@gustavdelius
Copy link
Member Author

@SamikDatta has just illustrated to me in an email why we need to use method dispatch for the mizer extension mechanism: currently two expansion packages that define their own rate functions which in turn utilise the mizer rate functions do not compose. The example Samik gives is therMizer not working together with mizerMR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Issue relates to the mizer core enhancement New feature requests or suggestions for enhancement of existing features
Projects
None yet
Development

No branches or pull requests

1 participant