You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Occasional it's useful to create a generic without `…` because such functions have a useful property: if a call succeeds for one type of input, it will succeed for any type of input.
116
116
To create such a generic, you'll need to use the third argument to `new_generic()`: an optional function that powers the generic.
117
-
This function has one key property: it must call `call_method()` to actually perform dispatch.
117
+
This function has one key property: it must call `S7_dispatch()` to actually perform dispatch.
118
118
119
119
In general, this property is only needed for very low-level functions with precisely defined semantics.
The most important part of the body is `S7_dispatch()`; this function finds the method the matches the arguments used for dispatch and calls it with the arguments supplied to the generic.
140
+
The most important part of the body is `S7_dispatch()`; this function finds the method that matches the arguments used for dispatch and calls it with the arguments supplied to the generic.
141
141
142
142
It can be useful to customize this body.
143
143
The previous section showed one case when you might want to supply the body yourself: dropping `…` from the formals of the generic.
@@ -147,7 +147,7 @@ There are three other useful cases:
147
147
- To add optional arguments.
148
148
- Perform some standard work.
149
149
150
-
A custom `fun` must always include a call to `call_method()`, which will usually be the last call.
150
+
A custom `fun` must always include a call to `S7_dispatch()`, which will usually be the last call.
151
151
152
152
### Add required arguments
153
153
@@ -213,7 +213,7 @@ The only downside to performing error checking is that you constraint the interf
213
213
214
214
## `super()`
215
215
216
-
Sometimes it's useful to define a method for in terms of its superclass.
216
+
Sometimes it's useful to define a method for a class that relies on the implementation for its superclass.
217
217
A good example of this is computing the mean of a date --- since dates represent the number of days since 1970-01-01, computing the mean is just a matter of computing the mean of the underlying numeric vector and converting it back to a date.
218
218
219
219
To demonstrate this idea, I'll first define a mean generic with a method for numbers:
@@ -256,8 +256,8 @@ This explicitness makes the code easier to understand and will eventually enable
256
256
257
257
## Multiple dispatch
258
258
259
-
So far we have focused primarily on single dispatch, i.e. generics where `dispatch_on` is a single string.
260
-
It is also possible to supply a length 2 (or more!) vector `dispatch_on` to create a generic that performs multiple dispatch, i.e. it uses the classes of more than one object to find the appropriate method.
259
+
So far we have focused primarily on single dispatch, i.e. generics where `dispatch_args` is a single string.
260
+
It is also possible to supply a length 2 (or more!) vector `dispatch_args` to create a generic that performs multiple dispatch, i.e. it uses the classes of more than one object to find the appropriate method.
261
261
262
262
Multiple dispatch is a feature primarily of S4, although S3 includes some limited special cases for arithmetic operators.
263
263
Multiple dispatch is heavily used in S4; we don't expect it to be heavily used in S7, but it is occasionally useful.
0 commit comments