[R] storing initial path for tkgetOpenFile
Erich Studerus
erich.studerus at bli.uzh.ch
Sun Oct 25 13:31:46 CET 2009
Hi,
I'd like to store the path from which I opened a file with tkgetOpenFile and
use it as the initial path for the next function call of tkgetOpenFile. What
is the best way of doing this? The following works fine on my Windows
computer. However, I'm not sure if it works on other platforms.
getFilename <- function (filename)
{
if (missing(filename)) {
temp.file <- paste(sub(".{10}$", "", tempdir()),
'getFilename.tmp', sep = "")
if (file.exists(temp.file)) {
initialdir <- readLines(temp.file, warn = FALSE)
} else {
initialdir <- getwd()
}
suppressMessages(require(tcltk, quietly = TRUE))
filename <- tclvalue(tkgetOpenFile(filetypes = "{{All} {.*}}",
initialdir = initialdir))
if (!nchar(filename)) {
stop('aborted')
}
if (initialdir != dirname(filename)) {
cat (dirname(filename), file = temp.file)
}
}
filename
}
getFilename()
More information about the R-help
mailing list