[R] Tcl Tk table

Peter Wolf s-plus at wiwi.uni-bielefeld.de
Mon Apr 26 10:54:04 CEST 2004


Hello Thomas,

sorry, I missed the point. James proposals work very well . I prefer the 
second one (b)

(a) 
eval(as.call(list(tkcmd,.Tk.ID(table1),"tag","celltag","gruen","5,5","6,6", 
"7,7", "8,8")))

(b) .Tcl(paste(.Tk.ID(table1),"tag celltag  gruen 3,3 4,4"))

Now we can define functions like

set.color<-function(widget,colorname,coords,rows,cols){
  # coords: string of type  "2,2 4,5 9,6" or
  # (rows,cols): rows and column number of the cells to be marked
  if(missing(coords)) coords<-paste(paste(rows,cols,sep=","),collapse=" ")
  .Tcl(paste(.Tk.ID(widget),"tag celltag ",colorname, coords))
  tkcmd(.Tk.ID(widget),"tag","configure",colorname,bg=colorname,fg="red")
}
set.color(table1,"blue", "2,1 3,4 5,2")
set.color(table1,"red", rows=3:1, cols=1:3)

Peter

James Wettenhall wrote:

> 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")))

thsudler at swissonline.ch wrote:

>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
>>>




More information about the R-help mailing list