zar*_*a77 5 user-interface dialog r
我choose.dir()在Windows XP下使用rscript.exe运行的脚本中使用该函数.问题是目录选择对话框不会弹出作为顶级窗口.如何将对话置于前台?
与此同时,我通过使用visual basic脚本解决了我的问题.当然,这只适用于Windows:
tf <- tempfile(fileext = '.vbs')
cat('Set folder = CreateObject("Shell.Application") _
.BrowseForFolder(0, "Please choose a folder" _
, &H0001, 17)
Wscript.Echo folder.Self.Path
', file = tf)
tail(shell(paste('Cscript', tf), intern = T), 1)
Run Code Online (Sandbox Code Playgroud)
搜索 rhelp 档案后,答案似乎是您不能在非交互式会话中使用choose.dirand 。file.choose您也许可以做类似的事情,因为list.files、file.info、file.access和files可用于收集信息,您可以通过写入图形设备并执行 system() 调用来显示它来显示它,并且 readLines 可用于获取用户输入。