[R] Having a problem with choose.files

Duncan Murdoch murdoch.duncan at gmail.com
Sun Mar 13 22:20:42 CET 2011


On 11-03-13 7:11 AM, Carl.Finkbeiner at tnsglobal.com wrote:
> I am relatively new to R, and am having a problem with the following
> snippet of code, and I do not at all understand why it is behaving this
> way.  I am running Windows XP, with R 2.12.1.
>
> I copy and paste these 4 lines into the R Console:
>    t<-c("a","b","c")
>    ans<-select.list(t)
>    txtNBS<-winDialogString("NBS","300")
>    choose.files()
>
> I click on OK in the Select One dialog, and on OK in the Question
> dialog, and then Cancel in the file dialog.  Everything behaves as I
> expect it to.  (All 3 of those dialog functions are in the utils
> package.)
>
> I then copy and paste these 6 lines defining the function fn, into the R
> Console.  Note that the body of the function is exactly the same as the
> 4 lines above that worked well.
>    fn<-function() {
>      t<-c("a","b","c")
>      ans<-select.list(t)
>      txtNBS<-winDialogString("NBS","300")
>      choose.files()
>    }

I think I know the details of the problem now.  The problem is that 
select.list()'s internal implementation didn't give R a chance to 
process messages after it was done, so its cleanup wasn't acted on at 
the right time.  (Event driven programming is lots of fun.)  When you 
run select.list() at the command line, R processes the cleanup after it 
is done, and things are fine.

This is easy to fix, and I'll do that in R-devel and R-patched.

I don't know an easy workaround in the meantime, other than not using 
the "graphics=TRUE" version of select.list ahead of other 
dialog-generating functions.

Duncan Murdoch

>
> When I then invoke this function by typing fn() into the R Console, I
> again click OK in the Select One dialog, and on OK in the Question
> dialog.  BUT, the file dialog never appears.  Furthermore, if I then
> type choose.files() into the R Console, about half the time the file
> dialog appears and about half the time it doesn't.
>
> Any help anyone can give me is much appreciated.  I cannot see what I am
> doing wrong here.
>
> Thanks,
>
> Carl Finkbeiner
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.



More information about the R-help mailing list