Title: | Keep Your Environment Clean |
---|---|
Description: | Provides a set of functions, which facilitates removing objects from an environment. It allows to delete objects specified with regular expression or with other conditions (e.g. if object is numeric), using one function call. |
Authors: | Krzysztof Joachimiak [aut, cre]
|
Maintainer: | Krzysztof Joachimiak <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2025-03-03 02:46:57 UTC |
Source: | https://github.com/krzjoa/eponge |
Provides a set of functions, which facilitates removing objects from an environment. It allows to delete objects specified with regular expression or with other conditions (e.g. if object is numeric), using one function call.
Krzysztof Joachimiak
Remove (all) objects from environment
erase(pattern = NULL, envir = parent.frame(), verbose = FALSE)
erase(pattern = NULL, envir = parent.frame(), verbose = FALSE)
pattern |
regex pattern to select a set of objects; default: NULL |
envir |
environment; default: caller environment |
verbose |
print removed objects' names |
Function can be used with envir = globalenv() argument.
NULL (function returns nothing)
create_data <- function() data.frame(a = 1:10, b = 11:20) x <- cars y <- 1:20 z <- function(x) x +2 # Typically, we don't have to specify enironment erase() ls()
create_data <- function() data.frame(a = 1:10, b = 11:20) x <- cars y <- 1:20 z <- function(x) x +2 # Typically, we don't have to specify enironment erase() ls()
Remove all objects, which are listed in 'Data' section in RStudio
erase_data(pattern = NULL, envir = parent.frame(), verbose = FALSE)
erase_data(pattern = NULL, envir = parent.frame(), verbose = FALSE)
pattern |
regex pattern to select a set of objects; default: NULL |
envir |
environment; default: caller environment |
verbose |
print removed objects' names |
Function can be used with envir = globalenv() argument.
NULL (function returns nothing)
cars.2 <- cars test_fun <- function(x) x + 2 value <- 7 erase_data(verbose = TRUE)
cars.2 <- cars test_fun <- function(x) x + 2 value <- 7 erase_data(verbose = TRUE)
Remove all the 'data.frame' objects
erase_df(pattern = NULL, envir = parent.frame(), verbose = FALSE)
erase_df(pattern = NULL, envir = parent.frame(), verbose = FALSE)
pattern |
regex pattern to select a set of objects; default: NULL |
envir |
environment; default: caller environment |
verbose |
print removed objects' names |
Function can be used with envir = globalenv() argument.
NULL (function returns nothing)
cars.2 <- cars test_fun <- function(x) x + 2 value <- 7 erase_df(verbose = TRUE)
cars.2 <- cars test_fun <- function(x) x + 2 value <- 7 erase_df(verbose = TRUE)
Remove (all) functions from environment
erase_functions(pattern = NULL, envir = parent.frame(), verbose = FALSE)
erase_functions(pattern = NULL, envir = parent.frame(), verbose = FALSE)
pattern |
regex pattern to select a set of objects; default: NULL |
envir |
environment; default: caller environment |
verbose |
print removed objects' names |
Function can be used with envir = globalenv() argument. Be careful: uncontrolled use may cause undesired side effects.
NULL (function returns nothing)
create_data <- function() data.frame(a = 1:10, b = 11:20) x <- cars y <- 1:20 z <- function(x) x +2 erase_functions() ls()
create_data <- function() data.frame(a = 1:10, b = 11:20) x <- cars y <- 1:20 z <- function(x) x +2 erase_functions() ls()
Remove objects, which fulfill determined conditions
erase_if(condition, pattern = NULL, envir = parent.frame(), verbose = FALSE)
erase_if(condition, pattern = NULL, envir = parent.frame(), verbose = FALSE)
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 |
Function can be used with envir = globalenv() argument.
NULL (function returns nothing)
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() # 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()
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() # 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()
Erase objects from GlobalEnv, which are masking objects from attached packages
erase_masking(pattern = NULL, verbose = FALSE) erase_masking_functions(pattern = NULL, verbose = FALSE)
erase_masking(pattern = NULL, verbose = FALSE) erase_masking_functions(pattern = NULL, verbose = FALSE)
pattern |
a regex pattern |
verbose |
print removed objects' names |
We have to highglight, that for now it only allows us to remove objects from the Global Environment. Be careful: uncontrolled use may cause undesired side effects.
NULL (function returns nothing)
# It works only if objects are assigned in the global environment matrix <- matrix(0, 3, 3) gamma <- 0.9 erase_masking()
# It works only if objects are assigned in the global environment matrix <- matrix(0, 3, 3) gamma <- 0.9 erase_masking()
Remove all the objects, that are not functions
erase_non_functions(pattern = NULL, envir = parent.frame(), verbose = FALSE)
erase_non_functions(pattern = NULL, envir = parent.frame(), verbose = FALSE)
pattern |
regex pattern to select a set of objects; default: NULL |
envir |
environment; default: caller environment |
verbose |
print removed objects' names |
Function can be used with envir = globalenv() argument.
NULL (function returns nothing)
cars.2 <- cars test_fun <- function(x) x + 2 value <- 7 erase_non_functions(verbose = TRUE)
cars.2 <- cars test_fun <- function(x) x + 2 value <- 7 erase_non_functions(verbose = TRUE)
Remove all objects, which are listed in 'Values' section in RStudio
erase_values(pattern = NULL, envir = parent.frame(), verbose = FALSE)
erase_values(pattern = NULL, envir = parent.frame(), verbose = FALSE)
pattern |
regex pattern to select a set of objects; default: NULL |
envir |
environment; default: caller environment |
verbose |
print removed objects' names |
Function can be used with envir = globalenv() argument.
NULL (function returns nothing)
cars.2 <- cars test_fun <- function(x) x + 2 value <- 7 erase_values(verbose = TRUE)
cars.2 <- cars test_fun <- function(x) x + 2 value <- 7 erase_values(verbose = TRUE)