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? Ivan -- Dr. Ivan Calandra TraCEr, laboratory for Traceology and Controlled Experiments MONREPOS Archaeological Research Centre and Museum for Human Behavioural Evolution Schloss Monrepos 56567 Neuwied, Germany +49 (0) 2631 9772-243 https://www.researchgate.net/profile/Ivan_Calandra On 03/03/2020 16:36, David Winsemius wrote:> > On 3/3/20 7:29 AM, Dennis Weygand wrote: >> How do I change the default directory that file.choose() (Windows-10) >> uses? > > > ?setwd > >
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
Thank you Duncan. I tried that through RStudio 1.2.5019 with R 3.6.2 on Win10. And what I did not mention is that I always cancelled the file.choose() actions, meaning I did not navigate to another folder. This does not quite fit what you said, but I might have misunderstood you, or RStudio overrides this behavior. I still find it strange that my second and third examples behave differently. Ivan -- Dr. Ivan Calandra TraCEr, laboratory for Traceology and Controlled Experiments MONREPOS Archaeological Research Centre and Museum for Human Behavioural Evolution Schloss Monrepos 56567 Neuwied, Germany +49 (0) 2631 9772-243 https://www.researchgate.net/profile/Ivan_Calandra On 03/03/2020 17:26, Duncan Murdoch wrote:> 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 > >
Hi Ivan I tried your examples and they behave as expected. Second one opens D:/ and third should be setwd("D:/Data/") to open in Data folder.> sessionInfo()R Under development (unstable) (2019-07-21 r76854) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 18363) So the problem is in your setting. Cheers Petr> -----Original Message----- > From: R-help <r-help-bounces at r-project.org> On Behalf Of Ivan Calandra > Sent: Tuesday, March 3, 2020 4:48 PM > To: r-help at r-project.org > Subject: Re: [R] file.choose() > > 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? > > Ivan > > -- > Dr. Ivan Calandra > TraCEr, laboratory for Traceology and Controlled Experiments MONREPOS > Archaeological Research Centre and Museum for Human Behavioural Evolution > Schloss Monrepos > 56567 Neuwied, Germany > +49 (0) 2631 9772-243 > https://www.researchgate.net/profile/Ivan_Calandra > > On 03/03/2020 16:36, David Winsemius wrote: > > > > On 3/3/20 7:29 AM, Dennis Weygand wrote: > >> How do I change the default directory that file.choose() (Windows-10) > >> uses? > > > > > > ?setwd > > > > > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
Thanks Petr for checking. This unexpected behavior is reproducible on my machine, both with the RGui and RStudio, both with R3.6.2 and 3.6.3.> sessionInfo()R version 3.6.3 (2020-02-29) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 18362) Matrix products: default locale: [1] LC_COLLATE=English_United Kingdom.1252? LC_CTYPE=English_United Kingdom.1252?? [3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C?????????????????????????? [5] LC_TIME=English_United Kingdom.1252??? attached base packages: [1] stats???? graphics? grDevices utils???? datasets? methods?? base???? loaded via a namespace (and not attached): [1] compiler_3.6.3 tools_3.6.3 Couldn't be that it behaves differently when the working directory is the root of the drive (D:/) vs. a folder on the drive (D:/Data)? Ivan ? -- Dr. Ivan Calandra TraCEr, laboratory for Traceology and Controlled Experiments MONREPOS Archaeological Research Centre and Museum for Human Behavioural Evolution Schloss Monrepos 56567 Neuwied, Germany +49 (0) 2631 9772-243 https://www.researchgate.net/profile/Ivan_Calandra On 04/03/2020 7:55, PIKAL Petr wrote:> Hi Ivan > > I tried your examples and they behave as expected. Second one opens D:/ and > third should be setwd("D:/Data/") to open in Data folder. > >> sessionInfo() > R Under development (unstable) (2019-07-21 r76854) > Platform: x86_64-w64-mingw32/x64 (64-bit) > Running under: Windows 10 x64 (build 18363) > > So the problem is in your setting. > > Cheers > Petr > >> -----Original Message----- >> From: R-help <r-help-bounces at r-project.org> On Behalf Of Ivan Calandra >> Sent: Tuesday, March 3, 2020 4:48 PM >> To: r-help at r-project.org >> Subject: Re: [R] file.choose() >> >> 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? >> >> Ivan >> >> -- >> Dr. Ivan Calandra >> TraCEr, laboratory for Traceology and Controlled Experiments MONREPOS >> Archaeological Research Centre and Museum for Human Behavioural Evolution >> Schloss Monrepos >> 56567 Neuwied, Germany >> +49 (0) 2631 9772-243 >> https://www.researchgate.net/profile/Ivan_Calandra >> >> On 03/03/2020 16:36, David Winsemius wrote: >>> On 3/3/20 7:29 AM, Dennis Weygand wrote: >>>> How do I change the default directory that file.choose() (Windows-10) >>>> uses? >>> >>> ?setwd >>> >>> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code.