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
Copy file name to clipboardExpand all lines: howMethodsWork.tex
+11-11
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@
28
28
29
29
\title{How S4 Methods Work}
30
30
\author{John Chambers}
31
-
31
+
\date{August 2006}
32
32
\begin{document}
33
33
\ifpdf
34
34
\DeclareGraphicsExtensions{.pdf, .jpg, .tif}
@@ -89,8 +89,8 @@ \section{Functions, Classes, and Object-oriented Programming}
89
89
Each method is stored within the generic function according to its \emph{signature}, which we can think of as a named list of classes, with the names corresponding to the formal arguments of the function. So for a function with arguments \SExpression{x} and \SExpression{y} (and perhaps others):
standardGeneric for "+" defined from package "base"
275
-
belonging to group(s): Arith
275
+
belonging to group(s): Arith
276
276
277
-
function (e1, e2)
277
+
function (e1, e2)
278
278
standardGeneric("+", .Primitive("+"))
279
279
<environment: 0x2b82eb0>
280
-
Methods may be defined for arguments: e1, e2
280
+
Methods may be defined for arguments: e1, e2
281
281
\end{Example}
282
282
The generic functions corresponding to primitives are kept in a list in the \SPackage{methods} package, and used for method dispatch and other computations, without being assigned in the ordinary way.
283
283
So long as computations access the generic function through \SFunction{getGeneric}, most computations should be unaffected.
Instead, encountering an object of primitive type for a method signals that there is no method defined for this signature.
294
294
The internal method search returns a special reference that tells the calling code in the evaluator to go on with the original built-in definition for the function.
295
295
Programmers do need to be careful when working with selected method definitions to be prepared for a primitive object.
standardGeneric for "[" defined from package "base"
307
307
308
-
function (x, i, j, ..., drop)
308
+
function (x, i, j, ..., drop)
309
309
standardGeneric("[", .Primitive("["))
310
310
<environment: 0x2a2207c>
311
-
Methods may be defined for arguments: x, i, j, drop
311
+
Methods may be defined for arguments: x, i, j, drop
312
312
\end{Example}
313
313
The argument \SExpression{drop} to the generic is only relevant for arrays; in addition, the argument \SExpression{j} is included to allow methods to depend on the class of the column index for two-way objects such as matrices or data frames.
314
314
@@ -412,7 +412,7 @@ \section{Earlier Versions of Method Selection}
0 commit comments