[R] Cleaning things up?

Guido Masarotto guido at sirio.stat.unipd.it
Tue Oct 17 16:11:29 CEST 2000

On Tue, Oct 17, 2000 at 09:06:11AM -0400, Yves Gauvreau wrote:
> Hi,
> I know it must be written somewhere but I can't find it.
> I'd like to remove all variables or objects that I've created but not the
> functions. I look at a few things without success. Is there a R way of doing
> this? There are to many to create a manual list.

You can try something like 

> ls()
> a<-1
> b<-2
> f<-function(x) x+1
> ls()
[1] "a" "b" "f"
> rm(list=ls()[!sapply(ls(),function(x)exists(x,mode="function"))])
> ls()
[1] "f"

but,..., be carefull, look  to the result of 'sapply' before doing
the true 'rm'.

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list