@@ -44,9 +44,9 @@ For details, see \link{S3Methods}.
4444In modern \R , a function \code {meth } in a package is registered as an S3 method
4545for function \code {fun } and class \code {Class } by
4646including in the package ' s \c ode{NAMESPACE} file the directive
47-
48- \c ode{ S3method(fun, Class, meth)}
49-
47+ \p reformatted{
48+ S3method(fun, Class, meth)
49+ }
5050By default (and traditionally), the third argument is taken to be the
5151function \c ode{fun.Class}; that is,
5252the name of the
@@ -63,9 +63,9 @@ register S3 methods rather than requiring the package to be attached.
6363
6464\s ection{Methods for S4 Classes}{
6565
66- Two possible mechanisms for implementing a method corresponding to an
67- S4 class, there are two possibilities are to register it as an S3 method with the
68- S4 class name or to define and set an S4 method, which will have the
66+ There are two possible mechanisms for implementing a method
67+ corresponding to an S4 class: register it as an S3 method with the
68+ S4 class name or define and set an S4 method, which will have the
6969side effect of creating an S4 generic version of this function.
7070
7171For most situations either works, but
@@ -79,20 +79,17 @@ extending \code{"character"} and intending to ignore upper- and
7979lower-case.
8080The base function \c ode{\l ink{unique}} dispatches S3 methods.
8181To define the class and a method for this function:
82-
83- \c ode{setClass("uncased", contains = "character")}
84-
85- \c ode{unique.uncased <- function(x, incomparables = FALSE, ...)
86- nextMethod(tolower(x))}
87-
88- \c ode{setMethod("unique", "uncased", unique.uncased)}
89-
82+ \p reformatted{
83+ setClass("uncased", contains = "character")
84+ unique.uncased <- function(x, incomparables = FALSE, ...)
85+ NextMethod(tolower(x))
86+ setMethod("unique", "uncased", unique.uncased)
87+ }
9088In addition, the \c ode{NAMESPACE} for the package should contain:
91-
92- \c ode{S3method(unique, uncased)}
93-
94- \c ode{exportMethods(unique)}
95-
89+ \p reformatted{
90+ S3method(unique, uncased)
91+ exportMethods(unique)
92+ }
9693The result is to define identical S3 and S4 methods and ensure that all
9794calls to \c ode{unique} will dispatch that method when appropriate.
9895}
0 commit comments