[Rd] surprising behaviour of names<-

Berwin A Turlach berwin at maths.uwa.edu.au
Sat Mar 14 12:24:34 CET 2009


On Sat, 14 Mar 2009 07:22:34 +0100
Wacek Kusnierczyk <Waclaw.Marcin.Kusnierczyk at idi.ntnu.no> wrote:

[...]
> > Well, I don't see any new object created in my workspace after
> > 	x <- 4
> > 	names(x) <- "foo"
> > Do you?
> >   
> 
> of course not.  that's why i'd say the two above are *not*
> equivalent. 
> 
> i haven't noticed the 'in the c code';  do you mean the r interpreter
> actually generates, in the c code, such r expressions for itself to
> evaluate?

As I said before, I have little knowledge about how the parser works and
what goes on under the hood; and I have also little time and
inclination to learn about it.  

But if you are interested in these details, then by all means invest
the time to investigate.

Alternatively, you would hope that Simon eventually finishes the book
that he is writing on programming in R; as I understand it, that book
would explain part of these issues in details.  Hopefully, along with
the book he makes the tools that he has for introspection available.

> >> i guess you have looked under the hood;  point me to the relevant
> >> code.     
> >
> > No I did not, because I am not interested in knowing such intimate
> > details of R, but it seems you were interested.
> >   
> 
> yes, but then your claim about what happens under the hood, in the c
> code, is a pure stipulation.  

I made no claim about what is going on under the hood because I have no
knowledge about these matters.  But, yes, I was speculating of what
might go on.

> and you got the example from the r language definition sec. 10.2,
> which says the forms are equivalent, with no 'under the hood, in the
> c code' comment.

Trying to figure out what a writer/painter actually means/says beyond
the explicitly stated/painted, something that is summed up in Australia
(and other places) under the term "critical thinking", was not high in
the curriculum of your school, was it? :-)

> you're just showing that your statements cannot be taken seriously.

Usually, my statement can be taken seriously, unless followed by some
indication that I said them tongue-in-cheek.  Of course, statements
that I allegedly made but were in fact put into my mouth cannot, and
should not, be taken seriously.

> >> yes, *if* you are able to predict the refcount of the object
> >> passed to 'names<-' *then* you can predict what 'names<-' will do,
> >> [...] 
> >
> > I think Simon pointed already out that you seem to have a wrong
> > picture of what is going on.  [...]
>
> so what you quote effectively talks about a specific refcount
> mechanism.  it's not refcount that would be used by the garbage
> collector, but it's a refcount, or maybe refflag.

Fair enough, if you call this a refcount then there is no problem.
Whenever I came across the term refcount in my readings, it was
referring to different mechanisms, typically mechanisms that kept exact
track on how often an object was referred too.  So I would not call the
value of the named field a refcount.  And we can agree to call it from
now on a refcount as long as we realise what mechanism is really used.
 
> yes, that's my opinion:  the effects of implementation tricks should
> not be observable by the user, because they can lead to hard to
> explain and debug behaviour in the user's program.  you surely don't
> suggest that all users consult the source code before writing
> programs in r.

Indeed, I am not suggesting this.  Only users who use/rely on
features that are not sufficiently documented would have to study the
source code to find out what the exact behaviour is.  But, of course,
this could be fraught with danger since the behaviour could change
without warning.

> i have indeed learned what prefix 'names<-' does and now i know that
> the surprising behaviour is due to the observability of the internal
> optimization.
> 
> thanks to simon, peter, and you for your answers which allowed me to
> learn this ugly detail.

You are welcome.

Cheers,

	Berwin



More information about the R-devel mailing list