Last active
August 3, 2022 17:09
-
-
Save jmbarbone/6b8877e6dbafe8ce94476875f07743bb to your computer and use it in GitHub Desktop.
Recursive detach
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
detach_recursive <- function(name, ...) { | |
stopifnot(!missing(name), is.character(name)) | |
params <- list(...) | |
params$name <- name | |
params$character.only <- TRUE | |
repeat { | |
if (inherits(try(do.call(detach, params), silent = TRUE), "try-error")) { | |
break | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
search() | |
#> [1] ".GlobalEnv" "package:stats" "package:graphics" | |
#> [4] "package:grDevices" "package:utils" "package:datasets" | |
#> [7] "package:methods" "Autoloads" "tools:callr" | |
#> [10] "package:base" | |
invisible(replicate(10, attach(iris, warn.conflicts = FALSE))) | |
search() | |
#> [1] ".GlobalEnv" "iris" "iris" | |
#> [4] "iris" "iris" "iris" | |
#> [7] "iris" "iris" "iris" | |
#> [10] "iris" "iris" "package:stats" | |
#> [13] "package:graphics" "package:grDevices" "package:utils" | |
#> [16] "package:datasets" "package:methods" "Autoloads" | |
#> [19] "tools:callr" "package:base" | |
detach_recursive("iris") | |
search() | |
#> [1] ".GlobalEnv" "package:stats" "package:graphics" | |
#> [4] "package:grDevices" "package:utils" "package:datasets" | |
#> [7] "package:methods" "Autoloads" "tools:callr" | |
#> [10] "package:base" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment