Вопрос

Is it possible to declare a variable btw. representation like "obj" of a arbitrary type, that means an ancestor, where all data types derived from? So that I can appropriate each type to representation type? Should I put this flexible parameter into a list?

setClass(Class = "MyClass",
         representation = representation(obj = "object"
                                         )
         )


new("MyClassA",name="abc",typ=123)
Это было полезно?

Решение

Yes, this is possible by setting the class of a slot to be ANY. For instance:

setClass('foo', slots = c(obj = 'ANY'))

Then the slot obj in the class foo can be used to store an object of any class.

Finally, the representation parameter to setClass was recently deprecated with version 3.0.0 of R, and you should use the slots parameter (as above) instead.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top