R-beta: scoping etc

Jim Lindsey (jlindsey@luc.ac.be)
Fri, 20 Feb 1998 11:51:45 +0100 (MET)


From: Jim Lindsey <jlindsey@luc.ac.be>
Message-Id: <9802201051.AA32068@alpha.luc.ac.be>
Subject: R-beta: scoping etc
To: r-help@stat.math.ethz.ch (r-help)
Date: Fri, 20 Feb 1998 11:51:45 +0100 (MET)

My problem with .RData almost a year ago is very similar to that of
attach in functions.
  If I remember correctly (I have not seen a .RData for a long time)
suppose that a .RData is loaded and contains a variable called y that
you have forgotten about (more probably you don't even notice that the
..RData was loaded).
  You create a dataframe (say read.table) containing a column labelled
y, planning to analyze the data. It is invisible because attached
behind the y from .RData and you unknowingly produce a completely
erroneous statistical analysis for your client or for publication.
(With luck, the two y's have incompatible lengths and a warning about
vectors not being multiples of each other's lengths will be produced -
when I had the problem, this warning was not yet available.)
  .RData is banned on our site.
  I do not think that functions should produce side effects (except
the few well-known ones). Attach should be local to a function and the
column names should not be hidden by objects outside its scope.
  For me, this question is now rather academic because I copy the
columns of the dataframe in the function instead of attaching (and
..RData never appears).
  Jim
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._