Skip to content
Prev 31857 / 63424 Next

surprising behaviour of names<-

Tony Plate wrote:
i must say that this part of the man page does explain things to me. 
much less the code [1] berwin suggested as a piece to read and
investigate (slightly modified):

    tmp = x
    x = 'names<-'(tmp, 'foo')

berwin's conclusion seemed to be that this code
hints/suggests/fortune-tells the user that 'names<-' might be doing side
effects. 

this code illustrates what names(x) = 'foo' (the infix form) does --
that it destructively modifies x.  now, if the code were to illustrate
that the prefix form does perform side effects too, then the following
would be enough:

    'names<-'(x, 'foo')

if the code were to illustrate that the prefix form, unlike the infix
form, does not perform side effects, then the following would suffice
for a discussion:

    x = 'names<-'(x, 'foo')

if the code wee to illustrate that the prefix form may or may not do
side effects depending on the situation, then it surely fails to show
that, unless the user performs some sophisticated inference which i am
not capable of, or, more likely, unless the user already knows that this
was to be shown.

without a discussion, the example is simply an unworked rubbish.  and
it's obviously wrong; it says that (slightly and irrelevantly simplified)

    names(x) = 'foo'

"is equivalent to"

    tmp = x
    x = 'names<-'(tmp, 'foo')

which is nonsense, because in the latter case you either have an
additional binding that you don't have in the former case, or, worse,
you rebind, possibly with a different value, a name that has had a
binding already.  it's a gritty-nitty detail, but so is most of
statistics based on nitty-gritty details which non-statisticians are
happy to either ignore or be ignorant about.


[1] http://stat.ethz.ch/R-manual/R-devel/doc/manual/R-lang.html#Comments
note, this 'because' does not follow in any way from the man page, or
the section of 'r language definition' referred to above.
it appears that

    set.names = function(n, x) 'names<-'(x, n)

would do the job (guess why).
i'm almost tempted to extend your recommendation to 'define your own
function for about every function already in r' ;)

vQ

Thread (49 messages)

Wacek Kusnierczyk surprising behaviour of names<- Mar 10 Peter Dalgaard surprising behaviour of names<- Mar 10 Wacek Kusnierczyk surprising behaviour of names<- Mar 10 Stavros Macrakis surprising behaviour of names<- Mar 10 Wacek Kusnierczyk surprising behaviour of names<- Mar 10 Wacek Kusnierczyk surprising behaviour of names<- Mar 10 Wacek Kusnierczyk surprising behaviour of names<- Mar 10 Simon Urbanek surprising behaviour of names<- Mar 11 Simon Urbanek surprising behaviour of names<- Mar 11 Wacek Kusnierczyk surprising behaviour of names<- Mar 11 Wacek Kusnierczyk surprising behaviour of names<- Mar 11 Berwin A Turlach surprising behaviour of names<- Mar 12 Berwin A Turlach surprising behaviour of names<- Mar 12 Wacek Kusnierczyk surprising behaviour of names<- Mar 12 Wacek Kusnierczyk surprising behaviour of names<- Mar 12 Wacek Kusnierczyk surprising behaviour of names<- Mar 12 Berwin A Turlach surprising behaviour of names<- Mar 12 Wacek Kusnierczyk surprising behaviour of names<- Mar 12 Berwin A Turlach surprising behaviour of names<- Mar 12 Wacek Kusnierczyk surprising behaviour of names<- Mar 12 Wacek Kusnierczyk surprising behaviour of names<- Mar 12 Wacek Kusnierczyk surprising behaviour of names<- Mar 12 Berwin A Turlach surprising behaviour of names<- Mar 12 Simon Urbanek surprising behaviour of names<- Mar 12 G. Jay Kerns surprising behaviour of names<- Mar 12 Wacek Kusnierczyk surprising behaviour of names<- Mar 12 Wacek Kusnierczyk surprising behaviour of names<- Mar 12 Joshua Ulrich surprising behaviour of names<- Mar 12 Wacek Kusnierczyk surprising behaviour of names<- Mar 12 Berwin A Turlach surprising behaviour of names<- Mar 12 Wacek Kusnierczyk surprising behaviour of names<- Mar 13 Berwin A Turlach surprising behaviour of names<- Mar 13 Wacek Kusnierczyk surprising behaviour of names<- Mar 13 William Dunlap surprising behaviour of names<- Mar 13 Tony Plate surprising behaviour of names<- Mar 13 Wacek Kusnierczyk surprising behaviour of names<- Mar 13 Wacek Kusnierczyk surprising behaviour of names<- Mar 13 Tony Plate surprising behaviour of names<- Mar 13 Wacek Kusnierczyk surprising behaviour of names<- Mar 13 Berwin A Turlach surprising behaviour of names<- Mar 13 Wacek Kusnierczyk surprising behaviour of names<- Mar 13 Thomas Lumley surprising behaviour of names<- Mar 14 Berwin A Turlach surprising behaviour of names<- Mar 14 Wacek Kusnierczyk surprising behaviour of names<- Mar 14 Wacek Kusnierczyk surprising behaviour of names<- Mar 15 Berwin A Turlach surprising behaviour of names<- Mar 15 Thomas Lumley surprising behaviour of names<- Mar 16 Wacek Kusnierczyk surprising behaviour of names<- Mar 16 Wacek Kusnierczyk surprising behaviour of names<- Mar 16