| Line 3... |
Line 3... |
| 3 |
% Copyright 1995-2007 R Core Development Team
|
3 |
% Copyright 1995-2007 R Core Development Team
|
| 4 |
% Distributed under GPL 2 or later
|
4 |
% Distributed under GPL 2 or later
|
| 5 |
|
5 |
|
| 6 |
\name{validObject}
|
6 |
\name{validObject}
|
| 7 |
\alias{validObject}
|
7 |
\alias{validObject}
|
| - |
|
8 |
\alias{getValidity}
|
| 8 |
\alias{setValidity}
|
9 |
\alias{setValidity}
|
| 9 |
\title{ Test the Validity of an Object }
|
10 |
\title{ Test the Validity of an Object }
|
| 10 |
\description{
|
11 |
\description{
|
| 11 |
The validity of \code{object} related to its class definition is
|
12 |
The validity of \code{object} related to its class definition is
|
| 12 |
tested. If the object is valid, \code{TRUE} is returned; otherwise,
|
13 |
tested. If the object is valid, \code{TRUE} is returned; otherwise,
|
| Line 22... |
Line 23... |
| 22 |
}
|
23 |
}
|
| 23 |
\usage{
|
24 |
\usage{
|
| 24 |
validObject(object, test = FALSE, complete = FALSE)
|
25 |
validObject(object, test = FALSE, complete = FALSE)
|
| 25 |
|
26 |
|
| 26 |
setValidity(Class, method, where = topenv(parent.frame()) )
|
27 |
setValidity(Class, method, where = topenv(parent.frame()) )
|
| - |
|
28 |
|
| - |
|
29 |
getValidity(ClassDef)
|
| 27 |
}
|
30 |
}
|
| 28 |
\arguments{
|
31 |
\arguments{
|
| 29 |
\item{object}{ any object, but not much will happen unless the
|
32 |
\item{object}{ any object, but not much will happen unless the
|
| 30 |
object's class has a formal definition.}
|
33 |
object's class has a formal definition.}
|
| 31 |
\item{test}{logical; if \code{TRUE} and validity fails, the
|
34 |
\item{test}{logical; if \code{TRUE} and validity fails, the
|
| Line 34... |
Line 37... |
| 34 |
an error.}
|
37 |
an error.}
|
| 35 |
\item{complete}{logical; if \code{TRUE}, validity methods will be
|
38 |
\item{complete}{logical; if \code{TRUE}, validity methods will be
|
| 36 |
applied recursively to any of the slots that have such methods.}
|
39 |
applied recursively to any of the slots that have such methods.}
|
| 37 |
\item{Class}{the name or class definition of the class whose validity
|
40 |
\item{Class}{the name or class definition of the class whose validity
|
| 38 |
method is to be set.}
|
41 |
method is to be set.}
|
| - |
|
42 |
\item{ClassDef}{a class definition object, as from
|
| - |
|
43 |
\code{\link{getClassDef}}.}
|
| 39 |
\item{method}{a validity method; that is, either \code{NULL} or a
|
44 |
\item{method}{a validity method; that is, either \code{NULL} or a
|
| 40 |
function of one argument (\code{object}). Like
|
45 |
function of one argument (\code{object}). Like
|
| 41 |
\code{validObject}, the function should return \code{TRUE} if the
|
46 |
\code{validObject}, the function should return \code{TRUE} if the
|
| 42 |
object is valid, and one or more descriptive strings if any problems
|
47 |
object is valid, and one or more descriptive strings if any problems
|
| 43 |
are found. Unlike \code{validObject}, it should never generate an
|
48 |
are found. Unlike \code{validObject}, it should never generate an
|
| Line 48... |
Line 53... |
| 48 |
|
53 |
|
| 49 |
Note that validity methods do not have to check validity of
|
54 |
Note that validity methods do not have to check validity of
|
| 50 |
superclasses: the logic of \code{validObject} ensures these tests are
|
55 |
superclasses: the logic of \code{validObject} ensures these tests are
|
| 51 |
done once only. As a consequence, if one validity method wants to use
|
56 |
done once only. As a consequence, if one validity method wants to use
|
| 52 |
another, it should extract and call the method from the other
|
57 |
another, it should extract and call the method from the other
|
| 53 |
definition of the other class by calling \code{\link{getValidity}}: it
|
58 |
definition of the other class by calling \code{getValidity()}: it
|
| 54 |
should \emph{not} call \code{validObject}.
|
59 |
should \emph{not} call \code{validObject}.
|
| 55 |
}
|
60 |
}
|
| 56 |
\details{
|
61 |
\details{
|
| 57 |
Validity testing takes place \sQuote{bottom up}: Optionally, if
|
62 |
Validity testing takes place \sQuote{bottom up}: Optionally, if
|
| 58 |
\code{complete=TRUE}, the validity of the object's slots, if any, is
|
63 |
\code{complete=TRUE}, the validity of the object's slots, if any, is
|
| Line 91... |
Line 96... |
| 91 |
differently in R. Also, there are extensions to the programming
|
96 |
differently in R. Also, there are extensions to the programming
|
| 92 |
interface developed more recently than the reference. For a
|
97 |
interface developed more recently than the reference. For a
|
| 93 |
discussion of details see \code{?\link{Methods}}
|
98 |
discussion of details see \code{?\link{Methods}}
|
| 94 |
and the links from that documentation.
|
99 |
and the links from that documentation.
|
| 95 |
}
|
100 |
}
|
| 96 |
\seealso{ \code{\link{setClass}}. }
|
101 |
\seealso{\code{\link{setClass}};
|
| - |
|
102 |
class \code{\linkS4class{classRepresentation}}.
|
| 97 |
|
103 |
}
|
| 98 |
\examples{
|
104 |
\examples{
|
| 99 |
setClass("track",
|
105 |
setClass("track",
|
| 100 |
representation(x="numeric", y = "numeric"))
|
106 |
representation(x="numeric", y = "numeric"))
|
| 101 |
t1 <- new("track", x=1:10, y=sort(stats::rnorm(10)))
|
107 |
t1 <- new("track", x=1:10, y=sort(stats::rnorm(10)))
|
| 102 |
## A valid "track" object has the same number of x, y values
|
108 |
## A valid "track" object has the same number of x, y values
|