所以我正在做的是制作我的浏览按钮,以便当我点击它们时,将用户直接带到我希望他们保存文件或查找文件的目录。
例如
setwd("C:\\Users\\Eric\\Desktop\\Program\\graphs") #set directory
file.choose()
但是在早期的脚本中,我已经将工作目录设置为
setwd("C:\\Users\\Eric\\Desktop\\Proram") #set directory
所以当我运行第一个例子时,它将我带到目录程序而不是图形。 但是当我第二次运行file.choose()时,它就把我带到了graph目录 为什么会这样?任何想法如何解决这个问题?
答案 0 :(得分:2)
这是解决问题的快速而肮脏的方法:
dirPath <- "C:\\Users\\Eric\\Desktop\\Program\\graphs"
setwd(dirPath)
# Tell R to sleep until the current directory matches the expected directory
while(getwd() != normalizePath(dirPath)) {
Sys.sleep(0.02)
}
file.choose()