philippe massicotte
2015-Feb-19 09:25 UTC
[R] Removing objects except user-defined functions
Dear R users. I would like to remove all object from my workspace except the function I have defined. However, is I use rm(list = ls()) everything is cleared. I was thinking to typeof to get information about objects, but I could not get it working right. Thank in advance, Phil [[alternative HTML version deleted]]
Stéphane Adamowicz
2015-Feb-19 09:33 UTC
[R] Removing objects except user-defined functions
There is a function keep() in package gdata for this purpose Le 19 f?vr. 2015 ? 10:25, philippe massicotte <pmassicotte at hotmail.com> a ?crit :> Dear R users. > > I would like to remove all object from my workspace except the function I have defined. However, is I use rm(list = ls()) everything is cleared. I was thinking to typeof to get information about objects, but I could not get it working right. > > Thank in advance, > Phil > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
On Thu, Feb 19, 2015 at 1:25 AM, philippe massicotte <pmassicotte at hotmail.com> wrote:> Dear R users. > > I would like to remove all object from my workspace except the function I have defined. However, is I use rm(list = ls()) everything is cleared. I was thinking to typeof to get information about objects, but I could not get it working right.names <- ls(envir=globalenv()) isfun <- sapply(names, FUN=exists, mode="function", envir=globalenv()) names <- names[!isfun] rm(list=c(names, "names", "isfun"), envir=globalenv()) /Henrik> > Thank in advance, > Phil > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.