[Rd] surprising behaviour of names<-
William Dunlap
wdunlap at tibco.com
Fri Mar 13 20:19:15 CET 2009
Would it make anyone any happier if the manual said
that the replacement functions should not be called
in the form
xNew <- `func<-` (xOld, value)
and should only be used as
func(xToBeChanged) <- value
?
The explanation
names(x) <- c("a","b")
is equivalent to
'*tmp*' <- x
x <- "names<-"('*tmp*', value=c("a","b"))
could also be extended a bit, adding a line like
rm(`*tmp*`)
Those 3 lines should be considered an atomic operation:
the value that `*tmp*` or `x` may have or what is
in the symbol table at various points in that sequence
is not defined. (Letting details be explicitly undefined
is important: it gives developers room to improve the
efficiency of the interpreter and tells users where not to go.)
Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com
> -----Original Message-----
> From: r-devel-bounces at r-project.org
> [mailto:r-devel-bounces at r-project.org] On Behalf Of Wacek Kusnierczyk
> Sent: Friday, March 13, 2009 11:42 AM
> To: Berwin A Turlach
> Cc: r-devel at r-project.org List
> Subject: Re: [Rd] surprising behaviour of names<-
> ... blah blah blah
> >> x = 1
> >> tmp = x
> >> x = 'names<-'(tmp, 'foo')
> >> names(tmp)
> >> # NULL
More information about the R-devel
mailing list