Hi I've a problem with the following example: library(tcltk) .Tcl("array unset tclArray") myRarray <- matrix(1:1000, ncol=20) for (i in (0:49)) for (j in (0:19)) .Tcl(paste("set tclArray(",i,",",j,") ",myRarray[i+1,j+1],sep="")) tt<-tktoplevel() table1 <- tkwidget(tt,"table",variable="tclArray", rows="50", cols="50") tkpack(table1) #Old version which worked in R 1.6 but it doesn't work with R 1.9 (and also not with 1.8), why?? tkcmd(.Tk.ID(table1),"tag","celltag","gruen",list(c("3,3", "4,4", "5,5", "6,6", "7,7", "8,8"))) tkcmd(.Tk.ID(table1),"tag","configure","gruen",bg="green",fg="green") #Error message: Error in switch(storage.mode(x), character = .External("RTcl_ObjFromCharVector", : Cannot handle object of mode list #But this works also with R 1.9 tkcmd(.Tk.ID(table1),"tag","celltag","gruen","3,3","4,4","5,5","6,6","7,7","8,8") tkcmd(.Tk.ID(table1),"tag","configure","gruen",bg="green",fg="green") Under R version 1.6 I had no problem. Now I installed R 1.9 (with ActiveTcl) and my program doesn't work. Maybe you ask why I?m not using the solution which works. It's because I've a list with thousands of coordiantes of cells which I want to have green, a list with thousands of coordinates of cells which I want to have blue, and so on. If I do this in a "for loop", it needs about 5 minutes until all the cells have the color I want (because it's a really big table). Also with "lapply" it needs about 3 minutes. In R version 1.6 (where it worked with a "list") the table was generated in less than 1 second! I would be very grateful if somebody could help me. Thanks a lot in advance! Thomas
thsudler at swissonline.ch wrote:>Hi > >I've a problem with the following example: > >library(tcltk) >.Tcl("array unset tclArray") > >myRarray <- matrix(1:1000, ncol=20) > >for (i in (0:49)) > for (j in (0:19)) > .Tcl(paste("set tclArray(",i,",",j,") ",myRarray[i+1,j+1],sep="")) > >tt<-tktoplevel() > >table1 <- tkwidget(tt,"table",variable="tclArray", rows="50", cols="50") > >tkpack(table1) > >#Old version which worked in R 1.6 but it doesn't work with R 1.9 (and also not with 1.8), why?? >..... >Under R version 1.6 I had no problem. Now I installed R 1.9 (with ActiveTcl) and my program doesn't work. ... >Thomas > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://www.stat.math.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > >Are you sure? > library(tcltk) > .Tcl("array unset tclArray") <Tcl> > > myRarray <- matrix(1:1000, ncol=20) > > for (i in (0:49)) + for (j in (0:19)) + .Tcl(paste("set tclArray(",i,",",j,") ",myRarray[i+1,j+1],sep="")) > > tt<-tktoplevel() > > table1 <- tkwidget(tt,"table",variable="tclArray", rows="50", cols="50") Error in structure(.External("dotTcl", ..., PACKAGE = "tcltk"), class = "tclObj") : [tcl] invalid command name "table". > > version _ platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major 1 minor 6.2 year 2003 month 01 day 10 language R the error occurs with version 1.6.2, too. Some debugging shows: the error message comes from tcl/tk and you need some additional features to be allowed to use the table-widget! you have to include: tclRequire("Tktable") ... and all is ok for 1.8.1 and I also hope for 1.9.0. see: http://bioinf.wehi.edu.au/~wettenhall/RTclTkExamples/tktable.html Peter Wolf
Hi Yes, I'm sure. I allready installed this additional package. The command tclRequire("Tktable") doesn't cause an error. So I've the Tktable package. But the command with "list" doesn't works: tkcmd(.Tk.ID(table1),"tag","celltag","gruen",list(c("3,3", "4,4", "5,5", "6,6", "7,7", "8,8"))) tkcmd(.Tk.ID(table1),"tag","configure","gruen",bg="green",fg="green") Error message: Error in switch(storage.mode(x), character = .External("RTcl_ObjFromCharVector", : Cannot handle object of mode list Do you know why this could be? Thomas ----- Original Message ----- From: "Peter Wolf" <s-plus at wiwi.uni-bielefeld.de> To: <thsudler at swissonline.ch>; <r-help at stat.math.ethz.ch> Sent: Friday, April 23, 2004 5:50 PM Subject: Re: [R] Tcl Tk table> thsudler at swissonline.ch wrote: > > >Hi > > > >I've a problem with the following example: > > > >library(tcltk) > >.Tcl("array unset tclArray") > > > >myRarray <- matrix(1:1000, ncol=20) > > > >for (i in (0:49)) > > for (j in (0:19)) > > .Tcl(paste("set tclArray(",i,",",j,") ",myRarray[i+1,j+1],sep="")) > > > >tt<-tktoplevel() > > > >table1 <- tkwidget(tt,"table",variable="tclArray", rows="50", cols="50") > > > >tkpack(table1) > > > >#Old version which worked in R 1.6 but it doesn't work with R 1.9 (and also not with 1.8), why?? > >..... > >Under R version 1.6 I had no problem. Now I installed R 1.9 (with ActiveTcl) and my program doesn't work. ... > >Thomas > > > >______________________________________________ > >R-help at stat.math.ethz.ch mailing list > >https://www.stat.math.ethz.ch/mailman/listinfo/r-help > >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > > > > Are you sure? > > > library(tcltk) > > .Tcl("array unset tclArray") > <Tcl> > > > > myRarray <- matrix(1:1000, ncol=20) > > > > for (i in (0:49)) > + for (j in (0:19)) > + .Tcl(paste("set tclArray(",i,",",j,") ",myRarray[i+1,j+1],sep="")) > > > > tt<-tktoplevel() > > > > table1 <- tkwidget(tt,"table",variable="tclArray", rows="50", cols="50") > Error in structure(.External("dotTcl", ..., PACKAGE = "tcltk"), class = > "tclObj") : > [tcl] invalid command name "table". > > > > version > _ > platform i686-pc-linux-gnu > arch i686 > os linux-gnu > system i686, linux-gnu > status > major 1 > minor 6.2 > year 2003 > month 01 > day 10 > language R > > the error occurs with version 1.6.2, too. > > Some debugging shows: the error message comes from tcl/tk and > you need some additional features to be allowed to use the table-widget! > you have to include: > > tclRequire("Tktable") > > ... and all is ok for 1.8.1 and I also hope for 1.9.0. > > see: http://bioinf.wehi.edu.au/~wettenhall/RTclTkExamples/tktable.html > > Peter Wolf > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
thsudler at swissonline.ch writes:> tkcmd(.Tk.ID(table1),"tag","celltag","gruen",list(c("3,3", "4,4", "5,5", "6,6", "7,7", "8,8")))Did that ever work? Prior to 1.8.0, a character vector would get expanded to multiple arguments, but not lists, AFAIR. The character vector expansion was sort of a nice feature in some cases, but it was was inconsistent with the rest of the design where one argument to tkcmd is one Tcl object (or two, for named arguments) and there were other cases where you'd want a character vector to be passed as a Tcl list. Also, the whole mechanism for converting from R to Tcl commands was horribly inefficient in some cases, and needed replacement. If you need to create a Tcl command with a variable number of arguments, you now need to create an R function call with a variable number of arguments, i.e. use do.call() as in do.call("tkcmd", c(list(table1,"tag","cell","gruen"), as.list(paste(3:8,3:8),sep=",")) (note btw that .Tk.ID() is wrong, you can just pass the widget itself) In a *really* tight spot, you can still get the old behaviour using .Tcl(.Tcl.args(.....))> #But this works also with R 1.9 > tkcmd(.Tk.ID(table1),"tag","celltag","gruen","3,3","4,4","5,5","6,6","7,7","8,8") > tkcmd(.Tk.ID(table1),"tag","configure","gruen",bg="green",fg="green")-- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Peter Dalgaard wrote:> do.call("tkcmd", c(list(table1,"tag","cell","gruen"), > as.list(paste(3:8,3:8),sep=",")) > > (note btw that .Tk.ID() is wrong, you can just pass the widget > itself)I think the sep="," should be inside the paste(3:8,3:8) brackets i.e. paste(3:8,3:8,sep=","), and there is a closing bracket missing at the end. The .Tk.ID() was probably copied from one of my examples. Oops. I must have been confusing tkcmd(...) with .Tcl(paste(...)) Just to expand on earlier answers, if the table widget has a Tk ID of .1.1, and you effectively want this Tcl command: .Tcl(".1.1 tag celltag gruen 3,3 4,4 5,5 6,6 7,7 8,8") then neither passing "3,3 4,4 5,5 6,6 7,7 8,8" to tkcmd nor passing c("3,3","4,4","5,5","6,6","7,7","8,8") to tkcmd will work because in both case the collection of cell-coordinate-pairs will be passed as a Tcl list which is one argument of the command whereas you want multiple arguments, i.e. it will be passed as this Tcl list: {3,3 4,4 5,5 6,6 7,7 8,8} or equivalently: "3,3 4,4 5,5 6,6 7,7 8,8" To get each cell-coordinate-pair passed as a separate argument, use do.call or eval(as.call(list(...))), for example: eval(as.call(list(tkcmd,.Tk.ID(table1),"tag","celltag", "gruen","3,3","4,4", "5,5","6,6", "7,7", "8,8"))) As noted previously, in R >= 1.8.0 tclArray() is a better way to handle Tcl arrays. Regards, James