Skip to content
Prev 57502 / 63421 Next

Should slot<-() alter its first argument?

The core of Bioconductor and the methods package itself once took
advantage of this "feature" to avoid unnecessary duplication. Since
the introduction of shallow copying, those abuses have been removed.

Note that these assignment functions always have issues due to
optimizations that assume <-() is called. For example,
@565446e0bdf8 25 S4SXP g0c0 [OBJ,NAM(1),S4,gp=0x10,ATT]
An object of class "Z"
Slot "x":
[1] "newest"
An object of class "Z"
Slot "x":
[1] "newest"

Since we assume <-() bumps NAMED, z2 has its NAMED cleared even though
it's obviously named:
@56544726ae60 25 S4SXP g0c0 [OBJ,NAM(1),S4,gp=0x10,ATT]
@56544726ae60 25 S4SXP g0c0 [OBJ,S4,gp=0x10,ATT]

So I guess we could make slot<-() a bit safer but unless we give up
the optimizations or maybe inform the "gets" functions that they are
being called outside of complex assignment, there will be exploits.

Michael

On Thu, Sep 19, 2019 at 11:19 AM William Dunlap via R-devel
<r-devel at r-project.org> wrote: