Search code examples
rquantmod

Removing NULL objects from an environment


I have an environment of objects that are either xts or NULL. I would like to remove all the NULL from the environment. Is there a function I can use with eapply to achieve this?


Solution

  • rm(
      list=names(
        which(
          sapply(globalenv(),is.null) # or .GlobalEnv
          )
        )
      )
    

    If it's not the global environment, you can use the envir switch in rm and wrap the environment name in getenv() in the sapply call