On 13/01/2008, Gabor Grothendieck <[EMAIL PROTECTED]> wrote:
> No.
>
> > f <- function(a = 3, b = 4) a-b
> > f(b = 10)
> [1] -7
> > f(b <- 10)
> [1] 6
>

I had to go and read (and re-read) the R manual on lexical scope to
try and understand this since this example highlights a previously
neglected "chasm" in my knowledge base!

Why does that give the result it does?

I can see that
f(b <- 10) is equivalent to   f(assign("b"), 10))

I can't work out whether that is interpreted within the parent
environment or the function's own environment at the time of call. Why
does R give the answer it does? This can't be a scope issue?  I would
have expected either -1 or -7!

Am I being completely dim?

-- 
Dr. Mark Wardle
Specialist registrar, Neurology
Cardiff, UK

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to