clear: Removes the variables from environment

View source: R/clear.R

clearR Documentation

Removes the variables from environment

Description

clear removes the variables, matched by the pattern, from the environment (the default is parent environment). It will return the name of variables which have been removed.

Usage

clear(pattern = "*", all.names = FALSE, envir = parent.frame())

Arguments

pattern

A character string. The regular expression pattern of variable names to be removed.

all.names

Logical. If TRUE, all object names are removed (except .Random.seed). If FALSE, object names which begin with a . are omitted.

envir

An alternative argument to name for specifying the environment.

Value

The name of variables which have been removed.

See Also

rm, https://github.com/paodan/funcTools

Examples

## Not run: 
# Remove all (visible) variables in the Global Environment.
x1 = 1
x3 = "a"
xx = TRUE
y = function(x) x
y1 = 1:4
yx = list(y = 1, x = 3)
.x = data.frame(rnorm(5))
ls(all.names = TRUE)
clear()
ls(all.names = TRUE)

# Remove all variables including (invisible) variables begin with a ".".
clear(all.names = TRUE)
ls(all.names = TRUE)

# Remove variables begin with "x".
x1 = 1
x3 = "a"
xx = TRUE
y = function(x) x
y1 = 1:4
yx = list(y = 1, x = 3)
.x = data.frame(rnorm(5))
clear("^x")
ls(all.names = TRUE)

# Remove variables end with "x".
clear("x$")
ls(all.names = TRUE)

## End(Not run)


paodan/funcTools documentation built on April 1, 2024, 12:01 a.m.