[R] goofy class question

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Wed Oct 12 09:59:59 CEST 2011


On Wed, Oct 12, 2011 at 8:46 AM, Erin Hodgess <erinm.hodgess at gmail.com> wrote:
> Dear R People:
>
> Here is a really goofy question.
>
> I have some objects which have 2 classes: data.frame and ucr.
>
> Also, the classes will always be in that order.
>
> I have tried all sorts of things, but to no avail.
>
> listucrModels <- function(envir=.GlobalEnv, ...) {
>    objects <- ls(envir=envir, ...)
>    if (length(objects) == 0) NULL
>    else objects[sapply(objects,
>       function(.x)  "ucr"==
>       (class(eval(parse(text=.x), envir=envir))[2]))]
>    }
>

 Can you get away with just testing inherits(x,"ucr") or "ucr" %in%
class(x)? Or do you really have to test that "ucr" is the second
element? Do you have objects of class "ucr" that aren't also of class
"data.frame"?



More information about the R-help mailing list