rfilechooser

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


When I change the working directory (e.g., from dir1 to dir2) then try to use choose.files(), the first time choose.files() runs it goes to dir1. If I cancel and run choose.files() a second time, then it opens in dir2. How can I get choose.files() to open in the most current working directory?

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

Here's an example:

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

I'd like to be able to use this progression to select a file from the current working directory. Appreciate any ideas. Thanks!


Solution

  • Try adding this mask to the default argument:

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

    From the help for ?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.