[Rd] `slot<-` performs an in-place modification
Hervé Pagès
hp@ge@@on@g|thub @end|ng |rom gm@||@com
Wed Mar 23 06:17:05 CET 2022
Hi,
I just found out that `slot<-` performs an in-place modification of the
object:
setClass("A", slots=c(stuff="ANY"))
x <- new("A", stuff=11:14)
y <- `slot<-`(x, "stuff", value=99)
Then:
y
# An object of class "A"
# Slot "stuff":
# [1] 99
x
# An object of class "A"
# Slot "stuff":
# [1] 99
That doesn't seem right!
Is this violation of the standard pass-by-value semantic somehow
intended here because most of the time people are expected to do
'slot(x, "stuff") <- 99' instead, in which case the violation cannot be
observed so does not matter? I didn't find anything in the man page
about this.
I see this behavior with R 4.1.3 and current R devel.
Thanks,
H.
--
Hervé Pagès
Bioconductor Core Team
hpages.on.github using gmail.com
More information about the R-devel
mailing list