Rev 52110 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
setClass("maybe")setClass("A", representation(x = "numeric"))setIs("A", "maybe",test = function(object)length(object@x) >= 1 && object@x[[1]] > 0,coerce = function(from)from,replace = function(from, value)stop("meaningless to replace the \"maybe\" part of an object"))aa <- new("A", x=1)ff <- function(x)"default ff"setGeneric("ff")ffMaybe <- function(x) "ff maybe method"setMethod("ff", "maybe", ffMaybe)aa2 <- new("A", x = -1) # condition not TRUEstopifnot(identical(ff(aa), "default ff"),identical(ff(aa2), "default ff"))# failed in R 2.11.0## a method to test the conditionsetMethod("ff", "A",function(x) {if(is(x, "maybe"))ffMaybe(x)elsecallNextMethod()})stopifnot(identical(ff(aa), "ff maybe method"),identical(ff(aa2), "default ff"))removeClass("A")removeClass("maybe")removeGeneric("ff")