Re: [R] More on global environment
You may want to look at the notes on and functions for workspace management that guide me. They can be downloaded from http://faculty.washington.edu/lunnebor/Stat342/ by checking on Exercises. I use the .GlobalEnv (position 1 on search path) solely for scratch and have project work attached further down the path. The two functions move() and rm.sv() contributed by my colleague John Miyamoto and described in the above make this easy to do. Michael Prager wrote: : Date: Thu, 15 Jul 2004 14:45:41 -0400 : From: Mike Prager [EMAIL PROTECTED] : Subject: [R] More on global environment : To: R Help list [EMAIL PROTECTED] : Message-ID: [EMAIL PROTECTED] : Content-Type: text/plain; charset=us-ascii; format=flowed : : To follow up on my previous question, suppose a user R session wants to : unload one workspace and load another within an R session. Is the : following the correct sequence? : (snip) : Michael Prager, Ph.D. : NOAA Center for Coastal Fisheries and Habitat Research : Beaufort, North Carolina 28516 : http://shrimp.ccfhrb.noaa.gov/~mprager/ ** Cliff Lunneborg, Professor Emeritus, Statistics Psychology, University of Washington, Seattle [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] More on global environment
Mike Prager wrote: At 7/15/2004 03:23 PM Thursday, Andy Liaw wrote: I've posted the following to R-help before. Hope it helps you. cd - function(dir = tclvalue(tkchooseDirectory()), saveOld=FALSE, loadNew=TRUE) { stopifnot(require(tcltk)) flush.console() What you want in a general function is if(.Platform$OS.type == windows) flush.console() Since flush.console() does not exist in any other version than the Windows versions of R. Uwe Ligges if (saveOld) save.image(compress=TRUE) setwd(dir) rm(list=ls(all=TRUE, envir=.GlobalEnv), envir=.GlobalEnv) if (loadNew file.exists(.RData)) { loaded - load(.RData, envir=.GlobalEnv) return(invisible(loaded)) } } [The tcltk part is based on Prof. Fox's help.] Andy Thanks! It's lovely. I added the call to flush.console() as shown, which (under Windows RGUI at least) issues the message that tcl is loading in a more timely way. Mike __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] More on global environment
That seems reasonable, although you might use rm(list = ls(all.names = TRUE)) if you are interested in removing objects whose names begin with a period. -roger Mike Prager wrote: To follow up on my previous question, suppose a user R session wants to unload one workspace and load another within an R session. Is the following the correct sequence? 1. save.image() to save the current workspace as .Rdata in the current working directory. 2. rm(list=ls()) to remove everything from the workspace. 3. setcwd(xxx) to set the new working directory. 4. load(.Rdata) to load the new workspace. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] More on global environment
I've posted the following to R-help before. Hope it helps you. cd - function(dir = tclvalue(tkchooseDirectory()), saveOld=FALSE, loadNew=TRUE) { stopifnot(require(tcltk)) if (saveOld) save.image(compress=TRUE) setwd(dir) rm(list=ls(all=TRUE, envir=.GlobalEnv), envir=.GlobalEnv) if (loadNew file.exists(.RData)) { loaded - load(.RData, envir=.GlobalEnv) return(invisible(loaded)) } } [The tcltk part is based on Prof. Fox's help.] Andy From: Mike Prager To follow up on my previous question, suppose a user R session wants to unload one workspace and load another within an R session. Is the following the correct sequence? 1. save.image() to save the current workspace as .Rdata in the current working directory. 2. rm(list=ls()) to remove everything from the workspace. 3. setcwd(xxx) to set the new working directory. 4. load(.Rdata) to load the new workspace. -- Michael Prager, Ph.D. NOAA Center for Coastal Fisheries and Habitat Research Beaufort, North Carolina 28516 http://shrimp.ccfhrb.noaa.gov/~mprager/ __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] More on global environment
At 7/15/2004 03:23 PM Thursday, Andy Liaw wrote: I've posted the following to R-help before. Hope it helps you. cd - function(dir = tclvalue(tkchooseDirectory()), saveOld=FALSE, loadNew=TRUE) { stopifnot(require(tcltk)) flush.console() if (saveOld) save.image(compress=TRUE) setwd(dir) rm(list=ls(all=TRUE, envir=.GlobalEnv), envir=.GlobalEnv) if (loadNew file.exists(.RData)) { loaded - load(.RData, envir=.GlobalEnv) return(invisible(loaded)) } } [The tcltk part is based on Prof. Fox's help.] Andy Thanks! It's lovely. I added the call to flush.console() as shown, which (under Windows RGUI at least) issues the message that tcl is loading in a more timely way. Mike __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html