Skip to content
Back to formatted view

Raw Message

Message-ID: <200304220407.h3M47dXu016904@r.hankin.sges.auckland.ac.nz>
Date: 2003-04-22T04:07:39Z
From: robin hankin
Subject: lexical scope

Hi everyone

another documented feature that was a bit unexpected for me:

R> x <- 19
R> f <- function(t){t+x}
R> f(100)
[1] 119

--as expected: x is visible from within f()
..but...


R> g <- function(a){x <- 1e99 ; return(f(a))}
R> g(4)
[1] 23

--the "x" that is visible from within g() is just 19, which is not the
  one I expected it to find.


R> rm(x)
R> g(4)
Error in f(a) : Object "x" not found

--g() looks in the first search path place and finds it empty,
  returning an error.


QUESTIONS:
Why doesn't g()  "keep looking" ?
How do I tell g() where to find x?
Where to look for documentation for this?

 

-- 

Robin Hankin, Lecturer,
School of Geography and Environmental Science
Tamaki Campus
Private Bag 92019 Auckland
New Zealand

r.hankin at auckland.ac.nz
tel 0064-9-373-7599 x6820; FAX 0064-9-373-7042