From jeffrey.horner at gmail.com  Thu Mar 10 16:40:04 2011
From: jeffrey.horner at gmail.com (Jeffrey Horner)
Date: Thu, 10 Mar 2011 09:40:04 -0600
Subject: [Rd] Testing for a reference class object
Message-ID: <AANLkTin4x5a3mWFqQBvcBgBmS5EFpi61uVet-Zda_rsZ@mail.gmail.com>

Hi all,

I've constructed the following function to test whether or not an
object was created from a reference class:

isRefClassObject <- function(x) isS4(x) &&
is.environment(attr(x,'.xData')) &&
exists('.refClassDef',attr(x,'.xData'))

but I'm unsure if it's a complete test or if there's a better way to
test. Regardless, It would be nice to have such a function in the
methods package.

I have a case where I'd like to ensure that an object is constructed
from a reference class AND that it implements a certain method:

if (isRefClassObject(x) && 'run' %in% getRefClass(x)$methods())
    x$run()

Thanks,

Jeff
-- 
http://biostat.mc.vanderbilt.edu/JeffreyHorner



[Rd] Testing for a reference class object
Jeffrey Horner