[R] Tktable change cell values
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Tue Jul 29 10:50:37 CEST 2003
James Wettenhall <wettenhall at wehi.edu.au> writes:
> Currently there is no official interface between R arrays and
> Tcl arrays, so you have to write your own.
>
> I've sketched some ideas on :
> http://bioinf.wehi.edu.au/~wettenhall/RTclTkExamples/tktable.html
>
> Here's a summary.
[implementation skipped]
> tt <- tktoplevel()
> tclArray <- tclArrayVar()
> tclArrayName <- ls(tclArray$env)
> table1 <- tkwidget(tt,"table",variable=tclArrayName)
> tkpack(table1)
>
> # Set/Modify the values of some cells.
> tclArray[0,0] <- "Zero"
> tclArray[0,1] <- "One"
> tclArray[1,0] <- "Two"
> tclArray[1,1] <- "Three"
>
> # Now get the value of a cell.
> tclArray[0,1]
I've been working on some array stuff for 1.8.0. It doesn't quite pan
out like the above because Tktable really uses arrays in a rather
special way.
A general Tcl array is more like a Perl hash, or an R environment (or
list with non-fixed length), so you want to be able to do A[["foo"]]
<- "bar", i.e. the index can be an arbitrary string. Tktable uses the
special indices "0,0" "0,1" ... to simulate a matrix.
Since it is probably useful to interface to the full capabilities of
Tcl arrays (every time I skip something, someone comes up with a case
where it is needed...), the thing that I have done works like
A <- tclArray()
A[["1,1"]] <- "blah" # autoconverts to tclObj
A[["1,1"]] # a tclObj
A$"1,1" # also works
The matrix-like items could be implememnted on top of this, but I'm a
little unsure precisely how, whether it would require a special class
or not, and whether one should implement the various forms of smart
indexing.
--
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
More information about the R-help
mailing list