how to bring the choose.file() dialog to the foreground
I'm using the function choose.dir()
in a script that is run with rscript.exe under Windows XP. The problem is that the directory choosing dialog does not pop up as a top-level window. How can I bring the dialogue to the foreground?
In the meantime, I solved my problem by using visual basic script. Of course, this only works with windows:
tf <- tempfile(fileext = '.vbs')
cat('Set folder = CreateObject("Shell.Application") _
.BrowseForFolder(0, "Please choose a folder"开发者_C百科 _
, &H0001, 17)
Wscript.Echo folder.Self.Path
', file = tf)
tail(shell(paste('Cscript', tf), intern = T), 1)
After searching the rhelp archives it appears the answer is that you can't use choose.dir
and file.choose
in a non-interactive session. You might be able to do something similar, since list.files
, file.info
, file.access
and files
can be used to gather information, you can display this by writing to a graphics device and executing a system() call to get it displayed, and readLines can be used to get user input.
精彩评论