Remove objects, which fulfill determined conditions

erase_if(condition, pattern = NULL, envir = parent.frame(),
  verbose = FALSE)

Arguments

condition

function or lambda expression (one side formula)

pattern

regex pattern to select a set of objects; default: NULL

envir

environment; default: caller environment

verbose

print removed objects' names

Value

NULL (function returns nothing)

Details

Function can be used with envir = globalenv() argument.

Examples

create_data <- function() data.frame(a = 1:10, b = 11:20) x <- cars y <- 1:20 z <- function(x) x +2 l <- list(1,2,3,4) erase_if(is.list) ls()
#> [1] "create_data" "y" "z"
# You may use lambda expression create_data <- function() data.frame(a = 1:10, b = 11:20) x <- cars y <- 1:20 z <- function(x) x +2 l <- list(1,2,3,4) erase_if(~ is.function(.x) | is.data.frame(.x)) ls()
#> [1] "l" "y"