Skip to content

Instantly share code, notes, and snippets.

@ctberthiaume
Last active September 5, 2020 00:35
Show Gist options
  • Save ctberthiaume/404974a3813cf026f0244a9fcb1df02e to your computer and use it in GitHub Desktop.
Save ctberthiaume/404974a3813cf026f0244a9fcb1df02e to your computer and use it in GitHub Desktop.
Find all object in basic RStudio search path
recursive_ls <- function(envir=NULL, use_names=FALSE) {
# Base case
if (identical(envir, emptyenv())) {
return(list())
}
if (is.null(envir)) {
envir <- parent.env(environment())
}
if (!use_names) {
objs <- ls(envir)
} else {
objs <- names(envir)
}
envobjects <- recursive_ls(parent.env(envir), use_names)
envobjects[[length(envobjects)+1]] <- objs
names(envobjects)[length(envobjects)] <- environmentName(envir)
return(envobjects)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment