나는 python의 'self'키워드 또는 java의 'this'키워드와 유사한 R을 찾고 있습니다. 다음 예제에서는 메소드에서 S4 객체를 만들고 있습니다. 다른 S4 개체 및 자신에게 포인터를 전달해야합니다. 이 일을 도와 줄 수있는 언어가 있습니까?'this'또는 'self'에 해당하는 R
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
}
)
)
나는 독립형 방법으로이 작업을 수행 할 수 있지만 S4는 랩 객체
이것은 "기준 클래스 '는 (?'ReferenceClasses' 또는'setRefClass')보다는 S4 클래스 자체 ('Classes', '? 방법'). ? ReferenceClasses에서, .self를 참조하십시오. –