Hi,

x <- 1L
class(x) <- c("myInt", "integer")
is(x)
Error in inherits(x, "factor") :
  argument "class2" is missing, with no default

The problem arises when is() is used with only one argument (object)
which has more than one class reported by class(object).
In the code is() does use variable "class2" before checking for its
presence.

Reversing the order of checks

is2 <- function(object, class2) {
 cl <- class(object)
 if (missing(class2))
 return(extends(cl))
 if (length(cl) > 1)
 return(class2 %in% cl)
 if (.identC(cl, class2) || .identC(class2, "ANY"))
         return(TRUE)
     ext <- possibleExtends(cl, class2)
     if (is.logical(ext))
         ext
     else if ([EMAIL PROTECTED])
         TRUE
     else [EMAIL PROTECTED](object)
}

is2(x)
[1] "myInt"   "integer"


This is not sufficient, though:

utils::data(npk, package="MASS")
ret <- aov(yield ~ block + N*P*K, npk)
is2(ret)
[1] "aov"      "lm"       "lm"       "mlm"      "oldClass" "oldClass"

with duplicate class names

due to
extends(class(ret))
[1] "aov"      "lm"       "lm"       "mlm"      "oldClass" "oldClass"

so something different would be needed.


Best,

  Matthias


> sessionInfo()
R version 2.7.0 RC (2008-04-15 r45347)
i686-pc-linux-gnu

locale:
[EMAIL 
PROTECTED];LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=C;[EMAIL
 PROTECTED];LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;[EMAIL 
PROTECTED];LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base


-- 
Matthias Burger                     Project Manager/ Biostatistician
Epigenomics AG    Kleine Praesidentenstr. 1    10178 Berlin, Germany
phone:+49-30-24345-371                          fax:+49-30-24345-555
http://www.epigenomics.com           [EMAIL PROTECTED]
--
Epigenomics AG Berlin           Amtsgericht Charlottenburg HRB 75861
Vorstand:   Geert Nygaard (CEO/Vorsitzender),  Dr. Kurt Berlin (CSO)
              Oliver Schacht PhD (CFO),  Christian Piepenbrock (COO)
Aufsichtsrat:   Prof. Dr. Dr. hc. Rolf Krebs (Chairman/Vorsitzender)

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to