Bug 15374 - [[<- with non-scalar index on lists introduces reference semantics
[[<- with non-scalar index on lists introduces reference semantics
Status: RESOLVED FIXED
Product: R
Classification: Unclassified
Component: Low-level
R 3.0.1
x86_64/x64/amd64 (64-bit) Linux
: P5 normal
Assigned To: R-core
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-07-02 15:33 UTC by Martin Morgan
Modified: 2013-07-03 17:19 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Morgan 2013-07-02 15:33:33 UTC
With

  l = list(list(1))
  l1 = l[[1]]
  l[[c(1, 1)]] = 2

we would not expect l1 to be modified, but it is

> stopifnot(l1 == 1)
Error: l1 == 1 is not TRUE

[[<- only duplicates the top-level object, and only when NAMED is 2. It instead needs to duplicate recursively, where the NAMED for a child is considered as max(NAMED(parent), NAMED(child)).

> R.version.string
[1] "R Under development (unstable) (2013-07-01 r63132)"
Comment 1 Luke Tierney 2013-07-03 17:19:04 UTC
Thanks for the report. Fixed for the trunk in r63166; in r63167 for R-3-0-patched.

This is fixed by having vectorIndex take an additional dup argument, FALSE when called from [[ and TRUE for [[<- calls. When TRUE substructure is duplicated as it is traversed if NAMED > 1.