Dear R-help, Can anyone tell me if it's possible to call up the "directory chooser" (the one you get when you click on "File" -> "Change Dir...") in Rgui from the R command line? Seems like file.choose() can't be used to choose a directory. This is in R-1.8.1 on WinXPPro. Any help much appreciated! Andy ------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments,...{{dropped}}
Liaw, Andy wrote:> Dear R-help, > > Can anyone tell me if it's possible to call up the "directory chooser" (the > one you get when you click on "File" -> "Change Dir...") in Rgui from the R > command line? Seems like file.choose() can't be used to choose a directory.Looks like there is no R function to do so. The C level code is in ./src/gnuwin32/rui.c and ./src/gnuwin32/graphapp/dialogs.c and friends. Uwe Ligges> This is in R-1.8.1 on WinXPPro. > > Any help much appreciated! > > Andy > > > > ------------------------------------------------------------------------------ > Notice: This e-mail message, together with any attachments,...{{dropped}} > > ______________________________________________ > R-help at 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
Thanks to Uwe and Duncan Murdoch (who replied off-list). The bottom line is as Uwe said: no existing R level functionality. I guess it might be possible to do something similar with Tcl/Tk, but I do not know Tcl/tk... Best, Andy> From: Uwe Ligges > > Liaw, Andy wrote: > > > Dear R-help, > > > > Can anyone tell me if it's possible to call up the > "directory chooser" (the > > one you get when you click on "File" -> "Change Dir...") in > Rgui from the R > > command line? Seems like file.choose() can't be used to > choose a directory. > > Looks like there is no R function to do so. > > The C level code is in > ./src/gnuwin32/rui.c > and > ./src/gnuwin32/graphapp/dialogs.c > and friends. > > Uwe Ligges > > > > This is in R-1.8.1 on WinXPPro. > > > > Any help much appreciated! > > > > Andy > > > > > > > > > -------------------------------------------------------------- > ---------------- > > Notice: This e-mail message, together with any > attachments,...{{dropped}} > > > > ______________________________________________ > > R-help at 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 at 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 > >------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments,...{{dropped}}
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> From: John Fox [mailto:jfox at mcmaster.ca] > > Dear Andy, > > At 02:29 PM 2/11/2004 -0500, Liaw, Andy wrote: > >Thanks to Uwe and Duncan Murdoch (who replied off-list). > The bottom line is > >as Uwe said: no existing R level functionality. > > > >I guess it might be possible to do something similar with > Tcl/Tk, but I do > >not know Tcl/tk... > > With the tcltk package loaded, it's as simple as > tclvalue(tkchooseDirectory()), which returns the directory name as a > character string. > > I hope that this helps, > John > > >Best, > >Andy > > > > > From: Uwe Ligges > > > > > > Liaw, Andy wrote: > > > > > > > Dear R-help, > > > > > > > > Can anyone tell me if it's possible to call up the > > > "directory chooser" (the > > > > one you get when you click on "File" -> "Change Dir...") in > > > Rgui from the R > > > > command line? Seems like file.choose() can't be used to > > > choose a directory. > > > > > > Looks like there is no R function to do so. > > > > > > The C level code is in > > > ./src/gnuwin32/rui.c > > > and > > > ./src/gnuwin32/graphapp/dialogs.c > > > and friends. > > > > > > Uwe Ligges > > > > > > > > > > This is in R-1.8.1 on WinXPPro. > > > > > > > > Any help much appreciated! > > > > > > > > Andy > > > > > > > > > > > > > > > > > > ----------------------------------------------------- > 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 > ----------------------------------------------------- > > >------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments,...{{dropped}}