Try choose.files choose.files(default = file.path(mydir, "*.*"), multi = FALSE)
On Wed, Dec 18, 2024 at 10:33 AM J C Nash <profjcn...@gmail.com> wrote: > > I've been working on a small personal project that needs to select files for > manipulation from > various directories and move them around in planned ways. file.choose() is a > nice way to select > files. However, I've noticed that if file.choose() is called within a > function, it is the > directory from which that calling function has been invoked that is displayed > by file.choose(). > > This is not altered if I setwd() within that function. Have I misunderstood > something or is this > an infelicity of file.choose(). sessionInfo() gives my system as > R version 4.4.2 (2024-10-31) > Platform: x86_64-pc-linux-gnu > Running under: Linux Mint 22 > > I've a small example script. It actually helps to create nd1 and nd2 and give > them some dummy > files before testing. > > Suggestions welcome. > > John Nash > > > # fcdir.R -- show directory being used by function that calls file choose > cpath<-getwd() > nd1<-paste0(cpath,"/nd1") > nd2<-paste0(cpath,"/nd2") > dir.create(nd1) > dir.create(nd2) > > myfc<-function(){ > cat("myfc working in ",getwd(),"\n") > val<-file.choose() > val > } > myfcd<-function(adir){ > setwd(adir) > cat("in myfcd, getwd() =", getwd(),"\n") > val<-file.choose() > val > } > > print(getwd()) > one<-myfc() > cat("one=",one,"\n") > setwd("nd1") > print(getwd()) > two<-myfc() # This opens file.choose() in nd1 > cat("two=",two,"\n") > setwd("..") > print(getwd()) > three<-myfcd("nd2") # But this does not > cat("three=",three,"\n") > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide https://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide https://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.