[R] Open directory within a menu in tcltk

Judith Flores juryef at yahoo.com
Tue Aug 19 03:11:04 CEST 2008


Hello,

    I am trying to setup a menu to open files and directories. I have the following code:




opendir<-function() {
  dirname<<-tclvalue(tkchooseDirectory())
}

openfile<-function() {
  filename<<-tclvalue(tkgetOpenFile())
}

require(tcltk)
t1<-tktoplevel()
topMenu<-tkmenu(t1)
tkconfigure(t1,menu=topMenu)

plotMenu<-tkmenu(topMenu, tearoff=FALSE)

tkadd(plotMenu,"command",label="Open file", command=openfile)
tkadd(plotMenu, "command",label="Select directory",command=opendir)
tkadd(plotMenu,"command",label="Quit", command=function() tkdestroy(t1))
tkadd(topMenu, "cascade", label="Menu",menu=plotMenu) 

tkfocus(t1)

  I can extract a file, but not a directory, I obtain the following error message:

Error in function ():
cannot change value of locked binding for 'dirname'.

  I would appreciate very much any help or explanation on this.

As always, thank you,

Judith



More information about the R-help mailing list