[R] update search path for attached data

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Jul 4 16:13:53 CEST 2008


On Fri, 4 Jul 2008, Ulrich Leopold wrote:

> Dear list,
>
> is there a way of updating the search path when using attach() for a data set.
>
> I am overwriting a variable in a data frame. To update teh search path I do
> the follwoing:
>
>> attach(dataset)
>> some data manipulation of dataset
>> detach(dataset)
>> attach(dataset) # to update the search path
>
> Is there a way to avoid the numerous detach() and attach() commands?

Not if 'dataset' is that data frame (you didn't actually say).  From the 
help page:

      The database is not actually attached.  Rather, a new environment
      is created on the search path and the elements of a list
      (including columns of a data frame) or objects in a save file or
      an environment are _copied_ into the new environment.  If you use
      '<<-' or 'assign' to assign to an attached database, you only
      alter the attached copy, not the original object.

So you can both change the data frame and assign the column to pos=2 to 
get the effect of what you appear to want.

> Thanks in advance,
> Ulrich Leopold



-- 
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