I'm making right now a R package and I have to chose between returning lists and an object with S3 attributes. The good thing, as for the lists, is that it's very easy to use for beginners, due to the dollar sign making all the elements easy to find. The bad thing, is that it removes direct inheritance (I'd like to return a ts object with some additional informations).
The alternative would be to set the dollar for my S3 class, like this example :
object <- 1
class(object) <- "MyClass"
attr(object,"MyAttribute") <- "This is a secret"
`$.MyClass` <- function(x,name) attr(object,name)
object$MyAttribute
However, I have 2 questions about this :
- Where to set the dollar partial matching function for the user to see "MyAttribute" as a valid choice in rstudio ?
- Besides, is that a fine practice to do so or should I keep on using simple lists
Thanks