Paulo Grahl <pgrahl <at> gmail.com> writes: > > Dear list members, > > Does anyone know how to use rm() to remove only variables but not > declared functions from the environment ? > I understand I could name all the functions with, let's say > "f_something", make sure that all variables do not start with "f_" and > then remove all BUT objects starting with "f_". > However, I have already defined all the functions and it would be > troublesome to change all of them to a new name. >
> a <- 1 > b <- 2 > d <- function(x) { x^2 } > objs <- ls() > objclasses <- sapply(objs,function(x) class(get(x))) > objclasses a b d "numeric" "numeric" "function" > rm(list=objs[objclasses!="function"]) > ls() [1] "d" "objclasses" "objs" > (objclasses and objs are left over, but a and b have been deleted) ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.