From ripley at stats.ox.ac.uk  Wed Jun 27 09:40:57 2007
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Wed, 27 Jun 2007 08:40:57 +0100 (BST)
Subject: [Rd] inherits() and virtual classes
In-Reply-To: <75FA4E14-86B6-4A11-A8B0-B0332C7E1FCB@noc.soton.ac.uk>
References: <75FA4E14-86B6-4A11-A8B0-B0332C7E1FCB@noc.soton.ac.uk>
Message-ID: <Pine.LNX.4.64.0706270835160.25210@auk.stats>

inherits() is not to do with S4 classes: it tests inheritance in the base 
class system.

See ?is in package 'methods'.

> is(jj, "onion")
[1] TRUE


On Wed, 27 Jun 2007, Robin Hankin wrote:

> Hi
>
> How do I test for an object having a particular virtual class?
>
> In the following, "onion" is a virtual class, and "octonion" is
> a non-virtual class contained in onion.  The last call
> to inherits() gives FALSE [R-2.5.0], when inherits.Rd led
> me to expect TRUE.
>
>
>
>
> setClass("onion",
>          representation = "VIRTUAL"
>          )
>
> setClass("octonion",
>          representation = representation(x="matrix"),
>          prototype      = list(x=matrix(numeric(),0,8)),
>          contains       = "onion"
>          )
>
>
> jj <- new("octonion",x=as.matrix(1:8))
>
> inherits(jj,"onion")
>
>
>
>
> --
> Robin Hankin
> Uncertainty Analyst
> National Oceanography Centre, Southampton
> European Way, Southampton SO14 3ZH, UK
>  tel  023-8059-7743
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



[Rd] inherits() and virtual classes
Prof Brian Ripley