I am looking for the equivalent of python's 'self' keyword or java's 'this' keyword in R. In the following example I am making an S4 object from a method of a different S4 object and need to pass a pointer to myself. Is there something in the language to help me do this?
MyPrinter <- setRefClass("MyPrinter",
fields = list(obj= "MyObject"),
methods = list(
prettyPrint = function() {
print(obj$age)
# do more stuff
}
)
)
MyObject <- setRefClass("MyObject",
fields = list(name = "character", age = "numeric"),
methods = list(
getPrinter = function() {
MyPrinter$new(obj=WHAT_GOES_HERE) #<--- THIS LINE
}
)
)
I can do this with a freestanding method but I was hoping for a nice object-oriented way of doing this operation in R. Thanks
?ReferenceClasses
or?setRefClass
) rather than S4 class per se (?Classes
,?Methods
). From ?ReferenceClasses, see.self
. – Sweetheart