\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)
\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.

\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 \code{base}
package (the last item in the search list).\end{Note}
\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()))

library(mva)
detach(2)# `pos' used for `name'
\end{ExampleCode}
\end{Examples}

