Pregunta
I have a question related to the creation of S4 classes in R. The "setClass" function has a named attribute "where" which defines where the metadata of the created class should be stored, according to the manual.
However, if I do the following
> en <- new.env(parent=emptyenv())
> setClass("A", representation(x="numeric"), where=en)
[1] "A"
Warning message:
In getPackageName(where) :
Created a package name, "2012-04-26 12:56:39", when none found
I can delete en using
> rm(en)
and am still able to use the class, e.g. with
> new("A", x=1)
An object of class "A"
Slot "x":
[1] 1
Why is that?
Thanks in advance,
Sven
Solución
The methods package caches the class definition in methods:::.classTable
, maybe for efficiency (class look-up) reasons. removeClass("A", where=en)
would remove both the cached version and the definition (though generating a spurious warning).
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow