Re: [R] update search path for attached data

From: Ulrich Leopold <uleopold_at_science.uva.nl>
Date: Sat, 05 Jul 2008 10:47:36 +0200 (CEST)

On Fri, 2008-07-04 at 15:13 +0100, Prof Brian Ripley wrote:
> 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.

How can I update directly the search path without using detach() attach() or '<<-' assign()?
Maybe using attach() or assign methods is not so convenient anyway in my case as it creates always a copy of each data set?

Is there a good practise in programming in R by using search paths but keep memory as well as updating of the search path to a minimum?

Ulrich

-- 
______________________________________________________________________

Ulrich Leopold

Resource Centre for Environmental Technologies, Public Research Centre
Henri Tudor, Technoport Schlassgoart, 66 rue de Luxembourg, P.O. BOX
144, L-4002 Esch-sur-Alzette, Luxembourg

tel: +352 425991 618
fax: +352 425991 601
mobile: +352 691 304813
http://www.crte.lu


Computational Bio- and Physical Geography, Institute for Biodiversity
and Ecosystem Dynamics, University of Amsterdam, Nieuwe Achtergracht
166, NL-1018WV Amsterdam, The Netherlands

http://www.science.uva.nl/ibed

______________________________________________
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.
Received on Sat 05 Jul 2008 - 08:54:16 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 05 Jul 2008 - 09:31:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive