为什么 choose.files() 不在当前工作目录中打开?

Why doesn't choose.files() open in the current working directory?

当我更改工作目录(例如,从 dir1 到 dir2)然后尝试使用 choose.files() 时,第一次 choose.files() 运行s 它转到 dir1。如果我再次取消并 运行 choose.files(),它会在 dir2 中打开。如何让 choose.files() 在最新的工作目录中打开?

I was encountering a different issue with file.choose() so I'm not able to use that function as a replacement

这是一个例子:

getwd()                # say this is dir1
setwd(choose.dir())    # here I change the wd to dir2
getwd()                # currently set to dir2
choose.files()         # this opens in dir1
choose.files()         # this time it opens in dir2

我希望能够使用此进程从当前工作目录 select 一个文件。感谢任何想法。谢谢!

尝试将此掩码添加到 default 参数:

choose.files(default=paste0(getwd(), "/*.*")) 

来自 ?choose.files 的帮助:

If you would like to display files in a particular directory, give a fully qualified file mask (e.g., "c:\*.*") in the default argument.