Skip to content

goofy class question

3 messages · Erin Hodgess, Joshua Wiley, Barry Rowlingson

#
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]))]
    }
[1] NA       NA       NA       NA       NA       NA       NA       NA
 [9] NA       NA       NA       NA       NA       "jan.df" NA       NA
[17] NA       NA       NA       NA       NA       NA       NA       NA
[25] NA       NA       NA       NA       NA       NA       NA       NA
Since most of them do not have the second class attribute.

How do I get rid of the NA's and just get a list, please?

Thanks,
Erin
#
names(lapply(.GlobalEnv, function(x) inherits(x, "ucr")))

HTH,

Josh
On Wed, Oct 12, 2011 at 12:46 AM, Erin Hodgess <erinm.hodgess at gmail.com> wrote:

  
    
#
On Wed, Oct 12, 2011 at 8:46 AM, Erin Hodgess <erinm.hodgess at gmail.com> wrote:
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"?