RE: [R] More on global environment

From: Liaw, Andy <andy_liaw_at_merck.com>
Date: Fri 16 Jul 2004 - 05:23:49 EST


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)   &nbsp; 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/
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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
>
>



R-help@stat.math.ethz.ch 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 Received on Fri Jul 16 05:45:47 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:55:00 EST