2

What I want to achieve

In order to build a generic framework i would like to build an s4 class with a slot that could be of any type. Is it possible? And if so how?

What I have found so far

I have found this question that adress the multiple types problem. But I would like to make it possible for any types not just some predefined types.

Example:

setClass("foo",
         representation(
           anything = "..."
         )
)

# I would like to be able to perform all of these
new("foo", anything = 1)
new("foo", anything = "a")
new("foo", anything = data.frame())
...
Emmanuel-Lin
  • 1,848
  • 1
  • 16
  • 31

1 Answers1

6

Yes, you could do something like:

setClass("hi", slots = c(slot1 = "ANY"))

The use of ANY is actually documented in the help.

RolandASc
  • 3,863
  • 1
  • 11
  • 30