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()
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.