Skip to content

how to get the GUI directory chooser on Windows?

1 message · Liaw, Andy

#
Fantastic!  Thanks very much, John.  Now I can use:

cd <- function(dir = tclvalue(tkchooseDirectory()), saveOld=FALSE,
               loadNew=TRUE) {
  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))
  }
}

so when I simply type cd() at the Rgui prompt, I can choose a directory,
click "OK", and have R switch to the new directory and load the workspace
image, if one is present.

[The code probably could use a bit more safeguard; e.g., checking that dir
is actually a valid directory, if given in the call to cd().]

Best,
Andy
------------------------------------------------------------------------------
Notice:  This e-mail message, together with any attachments,...{{dropped}}