[R] The assign function in R

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Jun 19 10:18:31 CEST 2008

For the record, frame=1 and where=1 are not the same thing (whereas 
frame=0 and where=0 are both the session database): assign() in S has both 
'frame' and 'where' arguments.

where=1 is the first database on the search() path, and is roughly 
equivalent to the workspace (although you can attach databases ahead of 
the working database in S(-PLUS), people who write code like where=1 often 
do not know that).

In S(-PLUS) there is a working database aka chapter, which is the nearest 
equivalent to the R workspace but is (conceptually) stored on disc and so 
permanent. It is like running R with --restore --save.  Unless some other 
database is attached at pos=1, the working database is at where=1.

The Blue Book contains the help page for assign() in S ca 1988, and apart 
from what where=0 means (which may well be a later addition) the 
information is all there.

On Thu, 19 Jun 2008, Peter Dalgaard wrote:

> Duncan Murdoch wrote:
>> Applejus wrote:
>>> Hello,
>>> I want to convert assign("a", b, where =1 ) from SPLUS to R.
>>> Is it safe to assume that the equivalent of where=1 is pos=1  in R?
>>> Thanks for help! 
>> Only a limited number of users here know what "where=1" means in S-PLUS. 
>> If one of those doesn't answer, you might want to explain that for those of 
>> us who have forgotten or who never knew.
> 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.
> --
>  O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
> c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
> (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
> ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-help mailing list