I’d like to remove all the objects from my current environment except two of them, something like this
rm(list=setdiff(ls(),c("current_object_a","current_object_b")))
but I’d like to call it within a function. If I do it now, nothing happens because I’m deleting the environment variables inside the function, not the global environment.
You have to specify the environment to both
lsandrm.But, really, why do you want to do this? Deleting things out of the global environment from within a function seems like a Bad Thing.