[ 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)

#  remove: Remove Objects from a Specified Environment

##  Description

` remove ` and ` rm ` can be used to remove objects. These can be specified
successively as character strings, or in the character vector ` list ` , or
through a combination of both. All objects thus specified will be removed.

If ` envir ` is NULL then the currently active environment is searched first.

If ` inherits ` is ` TRUE ` then parents of the supplied directory are
searched until a variable with the given name is encountered. A warning is
printed for each variable that is not found.

##  Usage

    
    
    remove(…, list = character(), pos = -1,
           envir = as.environment(pos), inherits = FALSE)
    
    rm    (…, list = character(), pos = -1,
           envir = as.environment(pos), inherits = FALSE)

##  Arguments

…

the objects to be removed, as names (unquoted) or character strings (quoted).

list

a character vector naming objects to be removed.

pos

where to do the removal. By default, uses the current environment. See
‘details’ for other possibilities.

envir

the ` [ environment ](/link/environment?package=base&version=3.6.2) ` to use.
See ‘details’.

inherits

should the enclosing frames of the environment be inspected?

##  Details

The ` pos ` argument can specify the environment from which to remove the
objects in any of several ways: 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 ` [ 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). The ` envir ` argument is an alternative way
to specify an environment, but is primarily there for back compatibility.

It is not allowed to remove variables from the base environment and base
namespace, nor from any environment which is locked (see ` [ lockEnvironment
](/link/lockEnvironment?package=base&version=3.6.2) ` ).

Earlier versions of  R  incorrectly claimed that supplying a character vector
in ` … ` removed the objects named in the character vector, but it removed the
character vector. Use the ` list ` argument to specify objects _via_ a
character vector.

##  References

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

##  See Also

` [ ls ](/link/ls?package=base&version=3.6.2) ` , ` [ objects
](/link/objects?package=base&version=3.6.2) `

##  Examples

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

    
    
    # NOT RUN {
    tmp <- 1:4
    ## work with tmp  and cleanup
    rm(tmp)
    
    # }
    # NOT RUN {
    ## remove (almost) everything in the working environment.
    ## You will get no warning, so don't do this unless you are really sure.
    rm(list = ls())
    # }
    

Run the code above in your browser using  [ DataCamp Workspace
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fremove&utm_source=r-docs&utm_medium=docs&utm_term=remove&utm_content=run_example_in_workspace)

Powered by  [ DataCamp ](https://www.datacamp.com/)