Sunday, December 23, 2012

R SCOPING RULES

R SCOPING RULES



REVISED: Saturday, March 2, 2013




R binding.

I. R BINDING

A. search( ) FUNCTION

The search list can be found by using the search( ) function. R first searches the "global environment" which is your workspace. Next R searches the namespaces of each of the packages in the search list. R has separate namespaces for functions and non-functions so it is possible to have an object named z and a function named z.  library( ) function is used to load a package.

B. SCOPING RULES

Scope means where do your variables have value.

Scoping rules determine how a value is associated with a free variable (global variable) in a function. R uses lexical or static scoping. R uses the search list to bind a value to a symbol.

A function + an environment = a closure or function closure.

An environment is a collection of symbol value pairs. The value of free variables is searched for in the environment in which the function was defined. Typically, a function is defined in the global environment, and the value of the free variable is found in the user's workspace.

In R you can have functions defined in the body of other functions. In R it is possible for a function to return another function.

You can determine a function's environment by calling the ls( ) function which gives you the object name and the function name. You can then call the get( ) function using the object name.

In lexical scoping the value of a free variable in a function is looked up in the environment in which the function was defined.

In dynamic scoping the value of a free variable in a function is looked up in the environment in which the function was called.

The parent frame is the calling environment in R.

When a function is defined in the global environment and subsequently called from the global environment, the defining environment and the calling environment are the same. This can sometimes give the appearance of dynamic scoping.

Other languages that support lexical scoping include:
Scheme
Pearl
Python
Common Lisp


In R all objects must be stored in memory. All functions must carry a pointer to their respective defining environments.

Enjoy R binding!

Elcric Otto Circle







-->




-->




-->

















How to Link to My Home Page

It will appear on your website as:

"Link to: ELCRIC OTTO CIRCLE's Home Page"

No comments:

Post a Comment