When implementing a generic method for a new class:
scale.newclass <- function(x, center = TRUE, scale = TRUE) {
...
}
How to guarantee that the default values for additional arguments center and scale always stay consistent with their default values in scale.default?
In other words - if in the future scale.default changes it's default argument to scale = FALSE, how to make sure scale.newclass defaults are also adjusted to match?
The method
scale.defaultinherits the default values of its arguments from the generic functionscale:Those values will not change unless the generic function changes, and if the generic function changes, then you'll be warned about inconsistencies by
R CMD check. So the example doesn't quite motivate the problem ...Setting that aside, you can do this programmatically with
formals<-:Well, that only works for generic functions not admitting a formal argument
...:In general, the formals of the two methods may not have the same length or the same names, and in that case you would want to be more careful:
Still, my feeling is that these kinds of "precautions" can cause more problems than they solve in the long run ...