Skip to content
Prev 165432 / 398506 Next

"assign" statement in S-Plus

If I remember correctly, frame 1 is the evaluation frame that comes into existence with each evaluation, then goes away at the end of the evaluation.  The main use of it is to get past the fact that S-PLUS searches the current functions variables, but not the ones the current function is nested in, so a person could assign something to frame 1, then call another function and that function could look for the variable in frame 1.

To do the same thing in R depends on what you are trying to accomplish.  In some cases the lexical scoping of R makes this completely unneeded.  If function g is defined inside of function f and function f assigns a value to 'prime' before function g is called, then function g will be able to see 'prime' in function f without any use of assign or frame 1.  If function g needs to change the value of 'prime', then <<- will work.

If function g is not defined inside of function f and they both need to see the same variable (and it cannot be passed as an argument), then one way to do this is to just insure that both functions inherit from the same environment.