Skip to content
Prev 147570 / 398500 Next

The assign function in R

Duncan Murdoch wrote:
Even some of those who should know may have forgotten by now... It is 
detailed in the Blue Book somewhere. As I recall it, the story is (or 
was?) that in S-PLUS objects are mostly on disk and the search path is a 
list of directories. Then there is a stack of evaluation frames plus two 
special frames, frame 0 and frame1. Frame 0 is permanent in the sense 
that it exists for the duration of the session, frame 1 exists during 
evaluation of expressions. Assignments to frame 1 were mostly done to 
overcome communication difficulties caused by the lack of lexical scope 
in S -- two different functions needing to work with the same temporary 
object would be the typical case.

I would conjecture that once the purpose of the assignment to frame 1 is 
understood, you can redesign the code so that it becomes much cleaner, 
possibly by using "<<-" semantics. For a quick port, what you need is 
some sort of temporary environment. Assigning to pos=1 is NOT the 
solution, because that is the global environment and you will  (A) risk 
clobbering an existing variable of the same name and (B) litter your 
workspace with intermediate results.