[R] Problem with data.frames

Simon Fear Simon.Fear at synequanon.com
Mon Aug 4 15:27:17 CEST 2003


Peter, Brian, and list,

sorry if I was not clear (and obviously I wasn't),  I do fully accept
that
different data frames *can* be given the same names. Then you'd have to
access the first one created with an explicit get() to some specific
point in
the search list - or explicitly placed there using pos= - if indeed you
could
remember which one you wanted.

I think my point is that duplicating names strikes me as horrendous
programming style - why on earth would I ever need to have two
deliberately
different objects coexisting with the same name?  Or the same object,
with
the same name, more than once?

Maybe I am missing the point in that I don't really use R interactively,
I
always source() or copy and paste to the prompt, so I probably think of
debugging structured programs more than some users.

If I can't convince everyone that this type of name duplication is best
treated as an error, surely a warning would be good? At least an
optional
argument ...

In Peter D's example, the second invocation of f() should presumably
create a
"new" d? That would suggest TWO new arguments, replace= and warn=.
Currently
both false. And Brian R. likes to have several tmp's. I just can't see
why.
(Well, actually, I can see that it saves the bother of detaching(), and
in an
interactive session with nobody looking over your shoulder, who cares?)
But
if I need more than one temporary dataframe I call them tmp1, tmp2, etc.
I
just don't like the idea of a load of old tmp's filling up my precious
memory
space and then not remembering which one was which. Surely it's a bug
waiting
to pounce (not sure about that metaphor, sorry).

SF


PS Before anyone tells me: name duplication is intentional and very
handy in
R - when writing and nesting functions. But then it is different.
Lexical
scope ensures that the most recently defined instance is used when the
name
is used (unless you do something psychopathic, such as use an explicit
assign
outside the current frame). But these local instances disappear when the
function closes. This is not the case for variables deliberately placed
in
the search path, which are meant to be "global", and in frame 1 (I
think. I'm
getting out of my depth here - spent too long using Splus).
In Peter D's example you have to be very careful that you don't assign
"x" in
.GlobalEnv else it will mask the one you probably wanted, which is d$x
or
get("x",pos=2) depending how many times you've called f().
I'm beginning to go off the idea of attach()ing dataframes altogether,
the
more I think about it.
 

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