The R Project SVN R

Rev

Rev 68948 | Rev 71229 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 68948 Rev 71228
Line 1... Line 1...
1
% File src/library/methods/man/validObject.Rd
1
% File src/library/methods/man/validObject.Rd
2
% Part of the R package, https://www.R-project.org
2
% Part of the R package, https://www.R-project.org
3
% Copyright 1995-2007 R Core Team
3
% Copyright 1995-2016 R Core 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{getValidity}
Line 96... Line 96...
96
\seealso{\code{\link{setClass}};
96
\seealso{\code{\link{setClass}};
97
  class \code{\linkS4class{classRepresentation}}.
97
  class \code{\linkS4class{classRepresentation}}.
98
}
98
}
99
\examples{
99
\examples{
100
setClass("track",
100
setClass("track",
101
          representation(x="numeric", y = "numeric"))
101
          slots = c(x="numeric", y = "numeric"))
102
t1 <- new("track", x=1:10, y=sort(stats::rnorm(10)))
102
t1 <- new("track", x=1:10, y=sort(stats::rnorm(10)))
103
## A valid "track" object has the same number of x, y values
103
## A valid "track" object has the same number of x, y values
104
validTrackObject <- function(object) {
104
validTrackObject <- function(object) {
105
    if(length(object@x) == length(object@y)) TRUE
105
    if(length(object@x) == length(object@y)) TRUE
106
    else paste("Unequal x,y lengths: ", length(object@x), ", ",
106
    else paste("Unequal x,y lengths: ", length(object@x), ", ",
Line 115... Line 115...
115
t2@x <- 1:20
115
t2@x <- 1:20
116
## This should generate an error
116
## This should generate an error
117
\dontrun{try(validObject(t2))}
117
\dontrun{try(validObject(t2))}
118
\dontshow{stopifnot(is(try(validObject(t2)), "try-error"))}
118
\dontshow{stopifnot(is(try(validObject(t2)), "try-error"))}
119
 
119
 
120
setClass("trackCurve",
120
setClass("trackCurve", contains = "track",
121
         representation("track", smooth = "numeric"))
121
         slots = c("track", smooth = "numeric"))
122
 
122
 
123
## all superclass validity methods are used when validObject
123
## all superclass validity methods are used when validObject
124
## is called from initialize() with arguments, so this fails
124
## is called from initialize() with arguments, so this fails
125
\dontrun{trynew("trackCurve", t2)}
125
\dontrun{trynew("trackCurve", t2)}
126
\dontshow{stopifnot(is(try(new("trackCurve", t2)), "try-error"))}
126
\dontshow{stopifnot(is(try(new("trackCurve", t2)), "try-error"))}
127
 
127
 
128
setClass("twoTrack", representation(tr1 = "track", tr2 ="track"))
128
setClass("twoTrack", slots = c(tr1 = "track", tr2 ="track"))
129
 
129
 
130
## validity tests are not applied recursively by default,
130
## validity tests are not applied recursively by default,
131
## so this object is created (invalidly)
131
## so this object is created (invalidly)
132
tT  <- new("twoTrack", tr2 = t2)
132
tT  <- new("twoTrack", tr2 = t2)
133
 
133