Possible Duplicate:
Is there a way to get a vector with the name of all functions that one could use in R?
Hi
I would like to get from R the list of functions loaded in the environment.
I know ls()
that gives the list of objects loaded. But some objects are not functions.
I would like to clean my env from the functions but not from the other objects (matrices, array etc) that contain some of my result that dont want to lose.
Any idea?
the objects() or ls() function can be used to get a vector of character strings of the names of all objects in the environment. The names in the result are sorted.
Global environment can be referred to as . GlobalEnv in R codes as well. We can use the ls() function to show what variables and functions are defined in the current environment. Moreover, we can use the environment() function to get the current environment.
You can do both by restarting your R session in RStudio with the keyboard shortcut Ctrl+Shift+F10 which will totally clear your global environment of both objects and loaded packages.
At the end of a session the objects in the global environment are usually kept in a single binary file in the working directory called . RData. When a new R session begins with this as the initial working directory, the objects are loaded back into memory.
See ?lsf.str
X <- lsf.str()
as.vector(X) # just for printing purposes, you can use the vector in rm()
rm(list=X)
ok, I have a proposal
rm(list=ls()[sapply(ls(), function(obj) "function"==class(eval(parse(text = obj)))[1])])
I am sure there is something more elegant.
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