[R] file.choose()

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Tue Mar 3 17:26:07 CET 2020

On 03/03/2020 10:47 a.m., Ivan Calandra wrote:
> That's what I was about to answer but tried first and it did not work.
> Now I tried more and noticed an unexpected behavior:
> getwd()
> [1] "C:/Users/.../Documents"
> file.choose() ## opens in "C:/Users/.../Documents" as expected
> setwd("D:/")
> getwd()
> [1] "D:/"
> file.choose() ## unexpectedly, opens in "C:/Users/.../Documents"
> setwd("D:/Data")
> getwd()
> [1] "D:/Data"
> file.choose() ## opens in "D:/Data" as expected
> Is that normal behavior?

If I recall correctly, the Windows GUI version opens the same directory 
as the user last selected (i.e. the dialog box remembers the last 
selection).   This was by design, because Windows users often start the 
GUI with the working directory being the R home directory, and rarely 
use setwd() to change it.

On Windows, I think you always get that version.  On other platforms it 
may depend on which front end you're using.

Duncan Murdoch

More information about the R-help mailing list