\Header{detach}{Detach Objects from the Search Path}
\keyword{data}{detach}
\begin{Description}\relax
Detach a database, i.e., remove it from the \code{\Link{search}()} path
of available \R{} objects. Usually, this either a \code{\Link{data.frame}}
which has been \code{\Link{attach}}ed or a package which was required
previously.\end{Description}
\begin{Usage}
\begin{verbatim}
detach(name, pos = 2, version)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{name}] The object to detach.  Defaults to \code{search()[pos]}.
This can be a name or a character string but \emph{not} a
character vector.

\item[\code{pos}] Index position in \code{\Link{search}()} of database to
detach.  When \code{name} is \code{\Link{numeric}}, \code{pos = name}
is used.

\item[\code{version}] A character string denoting a version number of the 
package to be loaded.  If no version is given, a suitable default
is chosen.
\end{ldescription}
\end{Arguments}
\begin{Value}
The attached database is returned invisibly, either as
\code{\Link{data.frame}} or as \code{\Link{list}}.\end{Value}
\begin{Note}\relax
You cannot detach either the workspace (position 1) or the \pkg{base}
package (the last item in the search list).\end{Note}
\begin{References}\relax
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
\emph{The New S Language}.
Wadsworth \& Brooks/Cole.\end{References}
\begin{SeeAlso}\relax
\code{\Link{attach}}, \code{\Link{library}}, \code{\Link{search}},
\code{\Link{objects}}.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
require(eda)#package
detach(package:eda)
## could equally well use detach("package:eda")
## but NOT  pkg <- "package:eda"; detach(pkg)
## Instead, use
library(eda)
pkg <- "package:eda"
detach(pos = match(pkg, search()))

## careful: do not do this unless 'lqs' is not already loaded.
library(lqs)
detach(2)# 'pos' used for 'name'
\end{ExampleCode}
\end{Examples}

