Skip to content
Prev 17457 / 63424 Next

Bug in copying of S4 objects (PR#8112)

I've poked in the source a bit.  Here are some notes in case someone
has time to look into this.

The main internal difference between <<- and <- for complex
assignments is that <- calls EnsureLocal which calls duplicate on the
value of the left hand side value if NAMED == 2.  In principle I don't
tink this should be necessary, but it means that assignment functions
called for <- assignments will not see NAMED == 2.  This protects
agains internal assignment functions that destructively modify without
looking at NAMED, which is what @<- and slot<- do.  But <<- does not
do this defensive duplicating, hence the problem with <<-.  Similar
problems occur if structures contain environments used to implement
reference behaviour since the copying stops at the environment.

The appropriate fix is to insure that @<- and slot<- respect NAMED and
duplicate when NAMED == 2, as attr<- does.  This will require either
making @<- and slot<- into SPECIALSXP's or some sort of
underhandedness to allow them to remain closures.  One possibility
might be to define a SPECIALSXP that looks at the NAMED value of the
object argument (by inspecting the promise before it is forced).  This
can then be passed into the internal R_set_slot function via .Call.

luke
On Thu, 1 Sep 2005, Luke Tierney wrote: