[Rd] residual '*tmp*' variable after "[<-" error

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Sep 21 00:10:11 CEST 2006

On Wed, 20 Sep 2006, Parlamis Franklin wrote:

> self-sanity check prior to filing a bug report:
> attempted replacement that generates an error leaves a '*tmp*'
> variable in the global environment.
> test <- 1:10
> test[2:4] <- expression(e)
> ls()
> i've read section 3.4.4 of the "R Language Definition" which
> discusses the mechanism for replacement, and it is not clear to me
> whether this was intended, but i suspect not (to be honest, it's not
> clear to me why the process as described doesn't generate an infinite
> recursion -- perhaps the primitive treats the argument named '*tmp*'
> different than other arguments).  i've also searched the R site, and
> can't find this particular issue discussed.
> even though, as below, i am using 2.4.0 alpha, this happens as well
> in 2.3.1.
> from my standpoint, desirable behavior would be:
> (i) if an error occurs, remove the '*tmp*' variable

That's a bug: it need a context set to clean up.

> (ii) report the error as occurring in the original replacement call
> (rather than the '*tmp*' replacement, which may be confusing to those
> who haven't read the "R Language Definition")

But by that point the call may have been transformed quite dramatically.
I was going to suggest traceback() would give you a sensible call, but in 
this case it is not doing so: at a quick glance that is also due to no 
context being set.

There is also the question as to whether this should have worked.  It 
probably could be made to do so as

test <- as.expression(test)
test[2:4] <- expression(e)

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-devel mailing list