How to remove all variables except functions in R
I have loaded different objects in R console and I can remove all of them using:
rm(list=ls())
removing only functions but not the variables:
rm(list=lsf.str())
but How can I remove all varaibles except the functions?
To remove all variables in r except for functions , you can use:
If you also want to remove objects whose names start with a period, use thisĀ instead: rm(list=setdiff(ls(all.names=TRUE), lsf.str(all.names=TRUE)))
Or use
rm(list = setdiff(ls(), lsf.str()))