[R] How do delete all R objects out off a function?

John Fox jfox at mcmaster.ca
Tue Mar 5 17:11:58 CET 2002

Dear Sven,

At 01:27 PM 3/5/2002 +0000, you wrote:
>how can I remove all R objects in the workspace out of a function?
>rm(list=ls()) doesn't work, and I've tried several pos arguments, but
>nothing worked.

This seems like a rather risky thing to do; however:

         > suicide <- function() rm(list=ls(.GlobalEnv) , envir=.GlobalEnv)
         > x <- y <- z <- 1
         > ls()
         [1] "suicide" "x"       "y"       "z"
         > suicide()
         > ls()

Is that what you had in mind? (Of course, the function need not reside in 
the global environment.)


John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox

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