Re: [R] Query concerning working directory for file.choose()

2024-12-19 Thread J C Nash

Thanks Duncan. The behaviour is tricky, and I'm still not sure I can predict 
it. Indeed,
I spent about an hour fiddling with file.choose(). It allows navigation across 
directories,
so is not totally without value. However, I've noticed users are very prone to 
making errors
when they aren't in the "right" place, and my application is for non-technical 
users. In fact,
it is a tool to help people pay bills and get documents online who are new to 
computing,
or at least to online processing of payments and reports (Canada Post strike in 
mind!)
and process them in a planned and orderly way so records are safely kept.
(Yes, I realize R is an odd choice, but is IS cross-platform, and the working 
example uses
YAD in Linux for the dialogs.) I'll welcome discussion of this project offline. 
Eventually
it should be on Github.

svDialogs seems promising, and I'm now exploring that, though I was 
disappointed to find
a note (on page 17 of 19 in the pdf manual no less) that "some functions are 
not working
yet in MacOS". Tests will be needed.

Cheers, John Nash



On 2024-12-18 13:39, Duncan Murdoch wrote:
I believe file.choose() remembers the last choice, and repeats that location the next time you call it. This is true 
when it is called at top level or from within a function.


The first time you call it in a session, it will default to the current working 
directory, but not after that.

Front ends are allowed to replace the underlying function, so that may depend on which front end you are using.  I'm 
talking about R.app on a Mac.


Duncan Murdoch

On 2024-12-18 10:32 a.m., J C Nash 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")

__
[email protected] 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.




__
[email protected] 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.


Re: [R] Query concerning working directory for file.choose()

2024-12-19 Thread peter dalgaard
Yes, this is different in RStudio, e.g.

I had actually forgotten how brain-dead the CLI version is:

> file.choose()
Enter file name: 

(Given that install.packages() fires up a Tcl/Tk chooser, users might 
reasonably expect us to do something at least slightly smarter).

- Peter

> On 18 Dec 2024, at 19:39 , Duncan Murdoch  wrote:
> 
> I believe file.choose() remembers the last choice, and repeats that location 
> the next time you call it. This is true when it is called at top level or 
> from within a function.
> 
> The first time you call it in a session, it will default to the current 
> working directory, but not after that.
> 
> Front ends are allowed to replace the underlying function, so that may depend 
> on which front end you are using.  I'm talking about R.app on a Mac.
> 
> Duncan Murdoch
> 
> On 2024-12-18 10:32 a.m., J C Nash 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")
>> __
>> [email protected] 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.
> 
> __
> [email protected] 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: [email protected]  Priv: [email protected]

__
[email protected] 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.


Re: [R] Query concerning working directory for file.choose()

2024-12-18 Thread Duncan Murdoch
I believe file.choose() remembers the last choice, and repeats that 
location the next time you call it. This is true when it is called at 
top level or from within a function.


The first time you call it in a session, it will default to the current 
working directory, but not after that.


Front ends are allowed to replace the underlying function, so that may 
depend on which front end you are using.  I'm talking about R.app on a Mac.


Duncan Murdoch

On 2024-12-18 10:32 a.m., J C Nash 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")

__
[email protected] 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.


__
[email protected] 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.


Re: [R] Query concerning working directory for file.choose()

2024-12-18 Thread Bert Gunter
choose.files is only for MS Windows (the Help file says).

-- Bert


On Wed, Dec 18, 2024 at 8:06 AM Gabor Grothendieck
 wrote:
>
> Try choose.files
>
> choose.files(default = file.path(mydir, "*.*"), multi = FALSE)
>
> On Wed, Dec 18, 2024 at 10:33 AM J C Nash  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")
> >
> > __
> > [email protected] 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
>
> __
> [email protected] 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.

__
[email protected] 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.


Re: [R] Query concerning working directory for file.choose()

2024-12-18 Thread Gabor Grothendieck
P.S.  That assumes Windows.

On Wed, Dec 18, 2024 at 11:02 AM Gabor Grothendieck
 wrote:
>
> Try choose.files
>
> choose.files(default = file.path(mydir, "*.*"), multi = FALSE)
>
> On Wed, Dec 18, 2024 at 10:33 AM J C Nash  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")
> >
> > __
> > [email protected] 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



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

__
[email protected] 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.


Re: [R] Query concerning working directory for file.choose()

2024-12-18 Thread Gabor Grothendieck
Try choose.files

choose.files(default = file.path(mydir, "*.*"), multi = FALSE)

On Wed, Dec 18, 2024 at 10:33 AM J C Nash  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")
>
> __
> [email protected] 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

__
[email protected] 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.