Rev 52030 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
## test (non-conditional) explicit inheritancesetClass("xy", representation(x="numeric", y="numeric"))setIs("xy", "complex",coerce = function(from) complex(real = from@x, imaginary = from@y),replace = function(from, value) {from@x <- Re(value)from@y <- Im(value)from})set.seed(124)x1 <- rnorm(10)y1 <- rnorm(10)cc <- complex(real = x1, imaginary=y1)xyc <- new("xy", x = x1, y = y1)stopifnot(identical(cc, as(xyc, "complex")))as(xyc, "complex") <- cc * 1istopifnot(identical(xyc, new("xy", x = -y1, y = x1)))setGeneric("size", function(x)standardGeneric("size"))setMethod("size", "vector", function(x)length(x))## class "xy" should inherit the vector method through complexstopifnot(identical(size(xyc), length(x1)))removeClass("xy")removeGeneric("size")