[R] The assign function in R

Peter Dalgaard p.dalgaard at biostat.ku.dk
Thu Jun 19 09:49:21 CEST 2008


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



More information about the R-help mailing list