The R Project SVN R

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
15357 jmc 1
\name{MethodsList}
2
\alias{MethodsList}
3
\alias{makeMethodsList}
4
\alias{SignatureMethod}
5
\alias{insertMethod}
20092 jmc 6
\alias{inheritedSubMethodLists}
15357 jmc 7
\alias{showMlist}
8
\alias{print.MethodsList}
16066 jmc 9
\alias{emptyMethodsList}
10
\alias{insertMethodInEmptyList}
16447 jmc 11
\alias{listFromMlist}
16764 jmc 12
\alias{linearizeMlist}
16471 jmc 13
\alias{finalDefaultMethod}
14
\alias{mergeMethods}
18558 jmc 15
\alias{loadMethod}
25816 jmc 16
\alias{loadMethod-methods}
17
\alias{loadMethod,ANY-method}
18
\alias{loadMethod,MethodDefinition-method}
19
\alias{loadMethod,MethodWithNext-method}
15357 jmc 20
\title{MethodsList Objects}
18994 hornik 21
\description{
22
  These functions create and manipulate \code{MethodsList} objects, the
23
  objects used in R to store methods for dispatch.  You should not call
24
  any of these functions from code that you want to port to S-Plus.
25
  Instead, use the functions described in the references.
26
}
15357 jmc 27
\usage{
28
MethodsList(.ArgName, ...)
29
 
30
makeMethodsList(object, level=1)
31
 
32
SignatureMethod(names, signature, definition)
33
 
21345 jmc 34
insertMethod(mlist, signature, args, def, cacheOnly)
15357 jmc 35
 
20092 jmc 36
inheritedSubMethodLists(object, thisClass, mlist, ev)
15357 jmc 37
 
16802 jmc 38
showMlist(mlist, includeDefs = TRUE, inherited = TRUE,
17000 jmc 39
   classes, useArgNames, printTo = stdout() )
15357 jmc 40
 
25433 hornik 41
\method{print}{MethodsList}(x, ...)
15357 jmc 42
 
16447 jmc 43
listFromMlist(mlist, prefix = list())
44
 
16802 jmc 45
linearizeMlist(mlist, inherited = TRUE)
16302 jmc 46
 
17688 jmc 47
finalDefaultMethod(mlist, fname = "NULL")
16471 jmc 48
 
22464 jmc 49
mergeMethods(m1, m2, genericLabel)
16471 jmc 50
 
18558 jmc 51
loadMethod(method, fname, envir)
52
 
15357 jmc 53
}
17454 jmc 54
 
55
\section{Details}{
56
 
18994 hornik 57
  \describe{
21353 maechler 58
 
59
    \item{\code{MethodsList}:}{
18994 hornik 60
      Create a MethodsList object out of the arguments.
15357 jmc 61
 
18994 hornik 62
      Conceptually, this object is a named collection of methods to be
63
      dispatched when the (first) argument in a function call matches
64
      the class corresponding to one of the names.  A final, unnamed
65
      element (i.e., with name \code{""}) corresponds to the default
66
      method.
15357 jmc 67
 
18994 hornik 68
      The elements can be either a function, or another MethodsList.  In
69
      the second case, this list implies dispatching on the second
70
      argument to the function using that list, given a selection of
71
      this element on the first argument.  Thus, method dispatching on
72
      an arbitrary number of arguments is defined.
15357 jmc 73
 
18994 hornik 74
      MethodsList objects are used primarily to dispatch OOP-style
75
      methods and, in R, to emulate S4-style methods.
76
    }
15357 jmc 77
 
21353 maechler 78
    \item{\code{SignatureMethod}:}{
18994 hornik 79
      construct a MethodsList object containing (only) this method,
19029 hornik 80
      corresponding to the signature; i.e., such that
81
      \code{signature[[1]]} is the match for the first argument,
82
      \code{signature[[2]]} for the second argument, and so on.  The
83
      string \code{"missing"} means a match for a missing argument, and
84
      \code{"ANY"} means use this as the default setting at this level.
15357 jmc 85
 
18994 hornik 86
      The first argument is the argument names to be used for dispatch
87
      corresponding to the signatures.
88
    }
15357 jmc 89
 
21353 maechler 90
    \item{\code{insertMethod}:}{
18994 hornik 91
      insert the definition \code{def} into the MethodsList object,
92
      \code{mlist}, corresponding to the signature.  By default, insert
21353 maechler 93
      it in the slot \code{"methods"}, but \code{cacheOnly=TRUE} inserts
94
      it into the \code{"allMethods"} slot (used for dispatch but not saved).
18994 hornik 95
    }
15357 jmc 96
 
21353 maechler 97
    \item{\code{inheritedSubMethodLists}:}{
18994 hornik 98
      Utility function to match the object  or the class (if the object
99
      is \code{NULL}) to the elements of a methods list.
100
      Used in finding inherited methods, and not meant to be called
101
      directly.
102
    }
15357 jmc 103
 
21353 maechler 104
    \item{\code{showMlist}:}{
18994 hornik 105
      Prints the contents of the MethodsList.  If \code{includeDefs} the
106
      signatures and the corresonding definitions will be printed;
107
      otherwise, only the signatures.
15357 jmc 108
 
18994 hornik 109
      The function calls itself recursively: \code{prev} is the
110
      previously selected classes.
111
    }
21353 maechler 112
 
18994 hornik 113
    \item{\code{listFromMlistForPrint}:}{
114
      Undo the recursive nature of the methods list, making a list of
115
      function defintions, with the names of the list being the
116
      corresponding signatures (designed for printing; for looping over
117
      the methods, use \code{\link{listFromMlist}} instead).
21353 maechler 118
 
18994 hornik 119
      The function calls itself recursively: \code{prev} is the
120
      previously selected classes.
121
    }
16302 jmc 122
 
18994 hornik 123
    \item{\code{finalDefaultMethod}:}{
124
      The true default method for the methods list object \code{mlist}
125
      (the method that matches class \code{"ANY"} for as many arguments
126
      as are used in methods matching for this generic function).  If
127
      \code{mlist} is null, returns the function called \code{fname}, or
128
      \code{NULL} if there is no such function.
129
    }
16471 jmc 130
 
18994 hornik 131
    \item{\code{mergeMethods}:}{
132
      Merges the methods in the second MethodsList object into the
133
      first, and returns the merged result.  Called from
22594 ripley 134
      \code{\link{getAllMethods}}.  For a primitive function,
135
      \code{genericLabel} is supplied as the name of the generic.
16471 jmc 136
    }
18994 hornik 137
 
138
    \item{\code{loadMethod}:}{
18558 jmc 139
      Called, if necessary, just before a call to \code{method} is
140
      dispatched in the frame \code{envir}.  The function exists so that
141
      methods can be defined for special classes of objects.  Usually
142
      the point is to assign or modify information in the frame
143
      environment to be used evaluation.  For example, the standard
144
      class \code{MethodDefinition} has a method that stores the target
25816 jmc 145
      and defined signatures in the environment.  Class
146
      \code{MethodWithNext} has a method taking account of the
147
      mechanism for storing the method to be used in a call to
148
      \code{\link{callNextMethod}}.
18558 jmc 149
 
150
      Any methods defined for \code{loadMethod} must return the function
151
      definition to be used for this call; typically, this is just the
152
      \code{method} argument.
18994 hornik 153
    }
154
  }
16066 jmc 155
}
15357 jmc 156
\details{
157
  Note that \code{MethodsList} objects represent methods only in the \R
158
  implementation.  You can use them to find or manipulate information about
159
  methods, but avoid doing so if you want your code to port to S-Plus.
160
}
161
\references{
25118 hornik 162
  The R package \pkg{methods} implements, with a few exceptions, the
163
  programming interface for classes and methods in the book
164
  \emph{Programming with Data} (John M. Chambers, Springer, 1998), in
165
  particular sections 1.6, 2.7, 2.8, and chapters 7 and 8.
15357 jmc 166
 
25118 hornik 167
  While the programming interface for the \pkg{methods} package follows
168
  the reference, the R software is an original implementation, so
169
  details in the reference that reflect the S4 implementation may appear
21345 jmc 170
  differently in R.  Also, there are extensions to the programming
171
  interface developed more recently than the reference.  For a
21353 maechler 172
  discussion of details and ongoing development, see the web page
21345 jmc 173
  \url{http://developer.r-project.org/methodsPackage.html} and the
174
  pointers from that page.
15357 jmc 175
}
16471 jmc 176
\keyword{internal}
177