[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  ls: List Objects

##  Description

` ls ` and ` 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, ` ls ` shows what data sets and functions a user has
defined. When invoked with no argument inside a function, ` ls ` returns the
names of the function's local variables: this is useful in conjunction with `
browser ` .

##  Usage

    
    
    ls(name, pos = -1L, envir = as.environment(pos),
       all.names = FALSE, pattern, sorted = TRUE)
    objects(name, pos= -1L, envir = as.environment(pos),
            all.names = FALSE, pattern, sorted = TRUE)

##  Arguments

name

which environment to use in listing the available objects. Defaults to the
_current_ environment. Although called ` name ` for back compatibility, in
fact this argument can specify the environment in any form; see the ‘Details’
section.

pos

an alternative argument to ` name ` for specifying the environment as a
position in the search list. Mostly there for back compatibility.

envir

an alternative argument to ` name ` for specifying the environment. Mostly
there for back compatibility.

all.names

a logical value. If ` TRUE ` , all object names are returned. If ` FALSE ` ,
names which begin with a  .  are omitted.

pattern

an optional [ regular expression
](/link/regular%20expression?package=base&version=3.6.2) . Only names matching
` pattern ` are returned. ` [ glob2rx
](/link/glob2rx?package=base&version=3.6.2) ` can be used to convert wildcard
patterns to regular expressions.

sorted

logical indicating if the resulting ` [ character
](/link/character?package=base&version=3.6.2) ` should be sorted
alphabetically. Note that this is part of ` ls() ` may take most of the time.

##  Details

The ` name ` argument can specify the environment from which object names are
taken in one of several forms: as an integer (the position in the ` [ search
](/link/search?package=base&version=3.6.2) ` list); as the character string
name of an element in the search list; or as an explicit ` [ environment
](/link/environment?package=base&version=3.6.2) ` (including using ` [
sys.frame ](/link/sys.frame?package=base&version=3.6.2) ` to access the
currently active function calls). By default, the environment of the call to `
ls ` or ` objects ` is used. The ` pos ` and ` envir ` arguments are an
alternative way to specify an environment, but are primarily there for back
compatibility.

Note that the _order_ of strings for ` sorted = TRUE ` is locale dependent,
see ` [ Sys.getlocale ](/link/Sys.getlocale?package=base&version=3.6.2) ` . If
` sorted = FALSE ` the order is arbitrary, depending if the environment is
hashed, the order of insertion of objects, ….

##  References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S Language_ .
Wadsworth & Brooks/Cole.

##  See Also

` [ glob2rx ](/link/glob2rx?package=base&version=3.6.2) ` for converting
wildcard patterns to regular expressions.

` [ ls.str ](/link/ls.str?package=base&version=3.6.2) ` for a long listing
based on ` [ str ](/link/str?package=base&version=3.6.2) ` . ` [ apropos
](/link/apropos?package=base&version=3.6.2) ` (or ` [ find
](/link/find?package=base&version=3.6.2) ` ) for finding objects in the whole
search path; ` [ grep ](/link/grep?package=base&version=3.6.2) ` for more
details on ‘regular expressions’; ` [ class
](/link/class?package=base&version=3.6.2) ` , ` [ methods
](/link/methods?package=base&version=3.6.2) ` , etc., for object-oriented
programming.

##  Examples

[ Run this code
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fls&utm_source=r-docs&utm_medium=docs&utm_term=ls&utm_content=r