在R的S4对象系统中,“this”(如Java或C++中)的等价物是什么 现在我知道R的S4对象系统与C++或java有很大的不同。

在R的S4对象系统中,“this”(如Java或C++中)的等价物是什么 现在我知道R的S4对象系统与C++或java有很大的不同。,r,s4,R,S4,然而,我有一个问题,在S4中是否有类似的方法定义在泛型和类上的分派上,而不是类上。因此,这始终是要调度的对象 .A = setClass("A", slots = c(a = "integer")) setGeneric("foo", function(x) standardGeneric("foo")) setMethod("foo", "A", function(x) { x@a # 'x' is the object that `foo()` dispatches

然而,我有一个问题,在S4中是否有类似的方法定义在泛型和类上的分派上,而不是类上。因此,这始终是要调度的对象

.A = setClass("A", slots = c(a = "integer"))

setGeneric("foo", function(x) standardGeneric("foo"))

setMethod("foo", "A", function(x) {
   x@a        # 'x' is the object that `foo()` dispatches on, i.e., 'this'
})
用法:

> y = .A(a=1:5)
> foo(y)
[1] 1 2 3 4 5

R不通过引用传递,至少在S4中不是这样,所以任何类型的指针的概念,特别是这个指针,都不会真正转换。