5

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?

Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
lab_notes
  • 407
  • 5
  • 11

1 Answers1

8
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

Brandon Bertelsen
  • 43,807
  • 34
  • 160
  • 255