More generally, I think one of the issues is that R is not yet able to decrement a reference count (or mark a 'shared' data object as 'unshared' after it knows only one binding to it exists). This means passing variables to R closures will mark that object as shared:
x <- list() .Internal(inspect(x)) # NAM(1) identity(x) .Internal(inspect(x)) # NAM(3) I think for this reason users often resort to 'hacks' that involve directly setting attributes on the object, since they 'know' only one reference to a particular object exists. I'm not sure if this really is 'safe', though -- likely not given potential future optimizations to R, as Tomas has alluded to. I think true reference counting has been implemented in the R sources, but the switch has not yet been flipped to enable that by default. Hopefully having that will make cases like the above work as expected? Thanks, Kevin On Wed, Sep 5, 2018 at 2:19 AM Iñaki Ucar <iu...@fedoraproject.org> wrote: > > The bottomline here is that one can always call a base method, > inexpensively and without modifying the object, in, let's say, > *formal* OOP languages. In R, this is not possible in general. It > would be possible if there was always a foo.default, but primitives > use internal dispatch. > > I was wondering whether it would be possible to provide a super(x, n) > function which simply causes the dispatching system to avoid "n" > classes in the hierarchy, so that: > > > x <- structure(list(), class=c("foo", "bar")) > > length(super(x, 0)) # looks for a length.foo > > length(super(x, 1)) # looks for a length.bar > > length(super(x, 2)) # calls the default > > length(super(x, Inf)) # calls the default > > Iñaki > ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel