[R] Clear all with/without function()

Duncan Murdoch murdoch at stats.uwo.ca
Wed Apr 8 12:47:02 CEST 2009


Taraxacum88 wrote:
> why 
>
> rm(list=ls(all=TRUE),envir=globalenv())
>
> is ok but
>
> ca<-function()  rm(list=ls(all=TRUE),envir=globalenv())
> ca()
>
> does not work?

ls(all=TRUE) from within your function lists all local variables, not 
globals.  You need envir=globalenv() there too.

Duncan Murdoch




More information about the R-help mailing list