The R Project SVN R

Rev

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

Rev 25816 Rev 26000
Line 81... Line 81...
81
  pointers from that page.
81
  pointers from that page.
82
}
82
}
83
\seealso{ \code{\link{setClass}}. }
83
\seealso{ \code{\link{setClass}}. }
84
 
84
 
85
\examples{
85
\examples{
86
  setClass("track",
86
setClass("track",
87
    representation(x="numeric", y = "numeric"))
87
          representation(x="numeric", y = "numeric"))
88
  t1 <- new("track", x=1:10, y=sort(rnorm(10)))
88
t1 <- new("track", x=1:10, y=sort(rnorm(10)))
89
  ## A valid "track" object has the same number of x, y values
89
## A valid "track" object has the same number of x, y values
90
  validTrackObject <- function(x){
90
validTrackObject <- function(x){
91
    if(length(x@x) == length(x@y)) TRUE
91
    if(length(x@x) == length(x@y)) TRUE
92
    else paste("Unequal x,y lengths: ", length(x@x), ", ", length(x@y),
92
    else paste("Unequal x,y lengths: ", length(x@x), ", ", length(x@y),
93
    sep="")
93
    sep="")
94
  }
94
}
95
  ## assign the function as the validity method for the class
95
## assign the function as the validity method for the class
96
  setValidity("track", validTrackObject)
96
setValidity("track", validTrackObject)
97
  ## t1 should be a valid "track" object
97
## t1 should be a valid "track" object
98
  validObject(t1)
98
validObject(t1)
99
  ## Now we do something bad
99
## Now we do something bad
100
  t1@x <- 1:20
100
t1@x <- 1:20
101
  ## This should generate an error
101
## This should generate an error
102
  \dontrun{try(validObject(t1))}
102
\dontrun{try(validObject(t1))}
103
 \testonly{stopifnot(is(try(validObject(t1)), "try-error"))}
103
\dontshow{stopifnot(is(try(validObject(t1)), "try-error"))}
104
}
104
}
105
 
105
 
106
\keyword{programming}
106
\keyword{programming}
107
\keyword{classes}
107
\keyword{classes}