How to remove all variables except functions in R

670    Asked by CarlPaige in Python , Asked on Jul 10, 2021

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?

Answered by Clare Matthews

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()))



Your Answer

Interviews

Parent Categories