From gunter.berton at gene.com  Sun Jul  7 06:36:49 2013
From: gunter.berton at gene.com (Bert Gunter)
Date: Sat, 6 Jul 2013 21:36:49 -0700
Subject: [Rd] The *tmp* variable
In-Reply-To: <CAJoaRhbsAUeKHO382L03buo7WGnKh=ysuq3Fn=bhfL04bKkHWQ@mail.gmail.com>
References: <CAJoaRhbsAUeKHO382L03buo7WGnKh=ysuq3Fn=bhfL04bKkHWQ@mail.gmail.com>
Message-ID: <CACk-te0C4oyVnREWgx5emCnQ_8KCxw8+G7zOhUNFO=3OP0-CuA@mail.gmail.com>

Peter:

(Your function doesn't work -- you need to specify runif(1))

What ambiguity?

In the assignment within f(), x <- x+1,

the "x" on the rhs is a free variable in the function, and is
therefore looked for in the environment where the function was
defined. The x on the lhs is defined within the function only.

No matter what f() returns, x remains 1 in the environment from which
f is called. The function does not "return x" -- it returns a value,
which you can assign as you wish.

So ???
(and apologies if I'm missing something obvious).

Cheers,
Bert

On Sat, Jul 6, 2013 at 9:11 PM, Peter Meilstrup
<peter.meilstrup at gmail.com> wrote:
> When complex assignments are performed, the R interpreter creates, then
> removes a special variable *tmp*. However, when byte compiling is enabled,
> it seems that a different mechanism for making compound assignments is used.
>
> Would it be possible to eliminate *tmp* from interpreted R code as well? It
> might be useful for a function to lock its own environment, and the
> appearance and disappearance of *tmp* generally precludes that.
>
> (For example, a function might lock its own environment to guard against
> lexical-scope-breaking ambiguities such as
>
> x <- 1
> f <- function() {
>    if (runif() < 0.5) {
>     x <- x+1
>   }
>   x
> }
>
> where it is not clear where the returned x comes from inside or outside f.)
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm



[Rd] The *tmp* variable
Bert Gunter