From simon.urbanek at r-project.org  Thu May 13 20:22:58 2010
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Thu, 13 May 2010 14:22:58 -0400
Subject: [Rd] What functions are called internally in R to resolve what
	variable is referred?
In-Reply-To: <AANLkTimZ57TV_geRPsAGB9CEBq6iv2V91EmFPMU1awQ0@mail.gmail.com>
References: <AANLkTimZ57TV_geRPsAGB9CEBq6iv2V91EmFPMU1awQ0@mail.gmail.com>
Message-ID: <CBCB3488-A73E-4D15-B69B-A1E5C54A2AE3@r-project.org>


On May 13, 2010, at 1:16 PM, thmsfuller066 at gmail.com wrote:

> Hello All,
> 
> If I refer to a variable 'x', 'x' will be searched in the current
> frame or the parent frame, or the parent of the parent frame, etc.,
> until it is found (or not found at all)? Could you please show me what
> code in R source that handles this? Is it in the C code or the R code?
> 

At R level it is done automatically during evaluation (but you can so something similar using get() function in R). Internally (in C), findVar(symbol, env) in src/main/envir.c does the job by using findVarInFrame3() recursively for parent environments. There is slight exception if you use x()   since that does a search with the restriction that x must be a function and thus uses findFun() instead.

Cheers,
Simon



[Rd] What functions are called internally in R to resolve what variable is referred?
Simon Urbanek