remove everything from environment except code example Example: how to keep only certian objects python rm(list=setdiff(ls(), "x"))