Search code examples
rr-s4

R S4 slots as lists of custom classes


Is it possible to have slots in a S4 class to be lists of another custom type? like

setClass("customClass", 
          representation(list(anotherCustomClass)
)

Solution

  • For those looking for an answer to this. No, there is no way to restrict a list in S4 to have elements of certain type. This actually makes sense, since lists in R are designed to contain any type of element, so why lists on S4 should be distinct?