The R Project SVN R

Rev

Rev 61444 | Rev 66282 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 61444 Rev 61853
Line 77... Line 77...
77
}
77
}
78
\value{
78
\value{
79
  The \code{\link{environment}} is returned invisibly with a
79
  The \code{\link{environment}} is returned invisibly with a
80
  \code{"name"} attribute.
80
  \code{"name"} attribute.
81
}
81
}
-
 
82
 
-
 
83
\section{Good practice}{
-
 
84
  \code{attach} has the side effect of altering the search path and this
-
 
85
  can easily lead to the wrong object of a particular name being found.
-
 
86
  People do often forget to \code{\link{detach}} databases.
-
 
87
 
-
 
88
  In interactive use, \code{\link{with}} is usually preferable to the
-
 
89
  use of \code{attach}/\code{detach}.
-
 
90
 
-
 
91
  In programming, functions should not change the search path unless
-
 
92
  that is their purpose.  Often \code{\link{with}} can be used within a
-
 
93
  function, but if not good practice is to
-
 
94
  \itemize{
-
 
95
    \item Always use a distinctive \code{name} argument, and
-
 
96
    \item To immediately follow the \code{attach} call by an
-
 
97
    \code{\link{on.exit}} call to \code{detach} using the distinctive name.
-
 
98
  }
-
 
99
  This ensures that the search path is left unchanged even if the
-
 
100
  function is interrupted or if code after the \code{attach} call
-
 
101
  changes the search path.
-
 
102
}
82
\references{
103
\references{
83
  Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
104
  Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
84
  \emph{The New S Language}.
105
  \emph{The New S Language}.
85
  Wadsworth & Brooks/Cole.
106
  Wadsworth & Brooks/Cole.
86
}
107
}