[R] Best way to remove all objects but leave the functions in a workspace.

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Tue Feb 7 19:43:40 CET 2012


Best? Probably not. No money back if this deletes everything by mistake:

remove(list=ls()[sapply(ls(),function(n){!is.function(get(n))})])

As a function, maybe:

clearNonF=function(e=.GlobalEnv){remove(list=ls(e)[sapply(ls(e),function(n){!is.function(get(n))})],envir=e)}

clearNonF() will clear out the current workspace. Maybe.

On Tue, Feb 7, 2012 at 4:13 PM, Keith Weintraub <kw1958 at gmail.com> wrote:
> I think the subject says it all.

Barry



More information about the R-help mailing list