Janko Thyson
2011-May-30 15:54 UTC
[Rd] Query super- and subclasses of a class: is there a better way than to use 'completeClassDefinition()'
Dear List,
when I first started to use S4 classes, I used the function
'completeClassDef()' in order to see the super- and subclasses of a
certain class:
setClass(Class="A", representation=list(a="numeric"))
setClass(Class="B", contains="A",
representation=list(b="character"))
# Super
x <- completeClassDefinition("B")
attributes(x)
names(x@contains)
# Sub
x <- completeClassDefinition("A")
attributes(x)
names(x@subclasses)
This also does the trick for Reference Classes for me. However, I
re-read the respective section on the help page and wondered if I should
be more careful about using this function for this purpose as the page says:
"|completeClassDefinition: |Completes the definition of |Class|,
relative to the class definitions visible from environment |where|. If
|doExtends| is |TRUE|, complete the super- and sub-class information.
This function is called when a class is defined or re-defined."
So here are my questions:
1) Is it safe to call 'completeClassDef()' explicitly or can anything be
"overwritten" by this?
2) Is there a better way to query the super-/subclasses of a certain
S4/Reference Class?
Best regards and I'd like to take this opportunity to express my
gratitude to everyone on this list who takes the time to provide such
great help!
Janko
--
------------------------------------------------------------------------
*Janko Thyson*
janko.thyson@googlemail.com <mailto:janko.thyson@googlemail.com>
Jesuitenstraße 3
D-85049 Ingolstadt
Mobile: +49 (0)176 83294257
This e-mail and any attachment is for authorized use by the intended
recipient(s) only. It may contain proprietary material, confidential
information and/or be subject to legal privilege. It should not be
copied, disclosed to, retained or used by any other party.
If you are not an intended recipient then please promptly delete this
e-mail and any attachment and all copies and inform the sender.
[[alternative HTML version deleted]]
Martin Morgan
2011-May-31 16:15 UTC
[Rd] Query super- and subclasses of a class: is there a better way than to use 'completeClassDefinition()'
On 05/30/2011 08:54 AM, Janko Thyson wrote:> Dear List, > > when I first started to use S4 classes, I used the function > 'completeClassDef()' in order to see the super- and subclasses of a > certain class:Hi Janko -- I think 'complete' is meant as an adverb here; what you might want is names(getClassDef("A")@subclasses) (see slotNames(class(getClassDef("A"))) for other useful info). Martin> > setClass(Class="A", representation=list(a="numeric")) > setClass(Class="B", contains="A", representation=list(b="character")) > # Super > x<- completeClassDefinition("B") > attributes(x) > names(x at contains) > # Sub > x<- completeClassDefinition("A") > attributes(x) > names(x at subclasses) > > This also does the trick for Reference Classes for me. However, I > re-read the respective section on the help page and wondered if I should > be more careful about using this function for this purpose as the page says: > "|completeClassDefinition: |Completes the definition of |Class|, > relative to the class definitions visible from environment |where|. If > |doExtends| is |TRUE|, complete the super- and sub-class information. > This function is called when a class is defined or re-defined." > > So here are my questions: > 1) Is it safe to call 'completeClassDef()' explicitly or can anything be > "overwritten" by this? > 2) Is there a better way to query the super-/subclasses of a certain > S4/Reference Class? > > Best regards and I'd like to take this opportunity to express my > gratitude to everyone on this list who takes the time to provide such > great help! > Janko > > > > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel-- Computational Biology Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: M1-B861 Telephone: 206 667-2793
Maybe Matching Threads
- Problem with setValidity() or resetClass() or ... ?
- Function "nsl()" missing in package utils
- Significant memory leak when using XML on Windows
- How can I write methods for 'as()'?
- Bug or feature: using "ANY" as a generic field class (was: '[R] Is there a (virtual) class that all R objects inherit from?)