[Rd] surprising behaviour of names<-
Wacek Kusnierczyk
Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Wed Mar 11 20:29:14 CET 2009
Simon Urbanek wrote:
> Wacek,
>
> Peter gave you a full answer explaining it very well. If you really
> want to be able to trace each instance yourself, you have to learn far
> more about R internals than you apparently know (and Peter hinted at
> that). Internally x=1 an x=c(1) are slightly different in that the
> former has NAMED(x) = 2 whereas the latter has NAMED(x) = 0 which is
> what causes the difference in behavior as Peter explained. The reason
> is that c(1) creates a copy of the 1 (which is a constant [=unmutable]
> thus requiring a copy) and the new copy has no other references and
> thus can be modified and hence NAMED(x) = 0.
simon, thanks for the explanation, it's now as clear as i might expect.
now i'm concerned with what you say: that to understand something
visible to the user one needs to "learn far more about R internals than
one apparently knows". your response suggests that to use r without
confusion one needs to know the internals, and this would be a really
bad thing to say.. i have long been concerned with that r unnecessarily
exposes users to its internals, and here's one more example of how the
interface fails to hide the guts. (and peter did not give me a full
answer, but a vague hint.)
vQ
More information about the R-devel
mailing list