Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the list of functions loaded in R's global environment [duplicate]

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?

like image 318
RockScience Avatar asked Feb 24 '11 10:02

RockScience


People also ask

What function can you use to list all of the objects in your R environment?

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.

How do I view global environment in R?

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.

How do I remove a function from the Global environment in R?

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.

Where is R Global environment stored?

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.


2 Answers

See ?lsf.str

X <- lsf.str()
as.vector(X) # just for printing purposes, you can use the vector in rm()
rm(list=X)
like image 109
Joris Meys Avatar answered Oct 19 '22 17:10

Joris Meys


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.

like image 38
RockScience Avatar answered Oct 19 '22 17:10

RockScience