[R] Problem with data.frames
Simon Fear
Simon.Fear at synequanon.com
Mon Aug 4 13:57:38 CEST 2003
What I meant by "like library()" is that this function ensures that a
library
(or should I say package?) does not get loaded twice / duplicated in the
search path. Of course attach() is not the same as library(). Nor is it
the
same as with() - I just thought it might be useful if the help pages
pointed
to each other. Because I have programmed for years using attach() and
detach() and only very recently discovered with() (which is nearly
always
what I want since I work mostly with scripts).
> So how can you tell if the data frame is on the search list
"my.dframe" %in% search() ?
Does anyone have an example of a case where attaching the same data
frame
twice would be useful?
Thanks Prof R. for (another) reminder to read the code - I'm always
forgetting to look there. RTFC, Simon!
SF
-----Original Message-----
From: Prof Brian Ripley [mailto:ripley at stats.ox.ac.uk]
Sent: 04 August 2003 12:06
To: Simon Fear
Cc: Peter Dalgaard BSA; Andreas Eckner; r-help at stat.math.ethz.ch
Subject: RE: [R] Problem with data.frames
On Mon, 4 Aug 2003, Simon Fear wrote:
> Peter is right, but there is a point here: it would be nice if
> attach(my.dframe) would do nothing - or at least warn - if my.dframe
was
> already in the search list. Like library(). Attaching twice is almost
It is not like library(). attach attaches a copy of the data frame, and
it can be altered subsequently. So how can you tell if the data frame is
on the search list. I suspect it is quite common to create an object
called `tmp' and put it on the search list for a while. library()
assumes
that you have not reinstalled a loaded package (and if you have you
would
get inconsistent results).
> bound
> to be an error?
Not at all.
> Of course in many circumstances it might be better to use with() than
> attach() - if you haven't come across with(), it works like attach()
> with an
> inbuilt detach() when the parentheses close.
>
> Aside 1: it would also be nice if ?attach pointed to ?with. Is this
kind
> of
> suggestion best sent to r-help or r-devel?
I don't see they do the same job, especially not in an interactive
session (which is when attach() is most usefully used in this way).
> Aside 2: is with() efficient, or does it create a copy of the dataset?
It does not create a copy, as you can see from the code (it uses a
three-argument eval).
--
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
Simon Fear
Senior Statistician
Syne qua non Ltd
Tel: +44 (0) 1379 644449
Fax: +44 (0) 1379 644445
email: Simon.Fear at synequanon.com
web: http://www.synequanon.com
Number of attachments included with this message: 0
This message (and any associated files) is confidential and\...{{dropped}}
More information about the R-help
mailing list