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?
remove and rm can be used to remove objects. These can be specified successively as character strings, or in the character vector list , or through a combination of both. All objects thus specified will be removed. If envir is NULL then the the currently active environment is searched first.
When you want to clear a single variable from the R environment you can use the “rm()” command followed by the variable you want to remove. variable: that variable name you want to remove.
If a list contains NULL then we might want to replace it with another value or remove it from the list if we do not have any replacement for it. To remove the NULL value from a list, we can use the negation of sapply with is. NULL.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With