\Header{ls}{List Objects}
\alias{objects}{ls}
\keyword{environment}{ls}
\begin{Usage}
\begin{verbatim}
ls(name, pos= -1, envir=pos.to.env(pos),
       all.names=FALSE, pattern)
objects(name, pos= -1, envir=pos.to.env(pos),
       all.names=FALSE, pattern)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\texttt{name}] the name of an attached object appearing
in the vector of names returned by \texttt{search}.
\item[\texttt{pos}] the index of an attached object in
the list returned by \texttt{search}.  Defaults to the \emph{current}
environment.
\item[\texttt{envir}] an evaluation environment.  Defaults to the one corresponding
to \texttt{pos}.
\item[\texttt{all.names}] a logical value.  If \texttt{TRUE}, all
object names are returned.  If \texttt{FALSE}, names which begin with a
``.'' are omitted.
\item[\texttt{pattern}] an optional regular expression, see \texttt{\Link{grep}}.
Only names matching \texttt{pattern} are returned.
\end{ldescription}
\end{Arguments}
\begin{Description}
\texttt{ls} and \texttt{objects} return a vector of character strings
giving the names of the objects in the specified environment.
When invoked with no argument at the top level prompt,
\texttt{ls} shows what data sets and functions a user has defined.
When invoked with no argument inside a function,
\texttt{ls} returns the names of the functions local variables.
This is useful in conjunction with \texttt{browser}.\end{Description}
\begin{SeeAlso}
\texttt{\Link{apropos}} (or \texttt{\Link{find}}) for finding objects in the
whole search path; \texttt{\Link{grep}} for more details on ``regular
expressions''; \texttt{\Link{class}}, \texttt{\Link{methods}}, etc. for
object-oriented programming.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
.Ob <- 1
ls(pat="O")
ls(pat="O", all = T)    # also shows ".[foo]"

# shows an empty list because inside myfunc no variables are defined
myfunc _ function() {ls()}
myfunc()

# define a local variable inside myfunc
myfunc _ function() {y_1; ls()}
myfunc()                # shows "y"
\end{ExampleCode}
\end{Examples}

