Re: [Rd] Testing for a reference class object

From: John Chambers <>
Date: Thu, 10 Mar 2011 09:47:29 -0800

There is a virtual class "refClass" that all reference classes subclass, so is(x, "refClass") is the natural test, as in:

 > foo <- setRefClass("foo", fields = "bar")
 > x <- foo$new()
 > is(x, "refClass")

[1] TRUE On 3/10/11 7:40 AM, Jeffrey Horner wrote:
> 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 mailing list Received on Thu 10 Mar 2011 - 17:51:39 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 11 Mar 2011 - 06:50:29 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive