[Rd] tkinsert (PR#4289)

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Thu Sep 25 09:22:46 MEST 2003

Mark.Bravington at csiro.au writes:

> In R-1.7.1, I used to be able to append a character vector to a 'tklistbox' with e.g.
> listio <- tklistbox( tktoplevel(), font='Courier', height=20, width=20, setgrid=TRUE)
> tkinsert( listio, 'end', letters[1:3])
> tkpack( listio,side='left', expand=TRUE, fill='both')
> and three items would be added to 'listio'. This doesn't work in
> R-devel-- it looks as if only a single paste-collapsed item is
> added. This might even be intentional, but seems undesirable!
> The old behaviour can be obtained by reproducing the R 1.7.1 instructions:
> .Tcl( .Tcl.args( listio, 'insert', 'end', letters[1:3]))

So someone found out... 

This is just about the only incompatible change with the new Tcl_Objv
interface. The old way was one of those things that looked like a good
idea when written (to support exactly that situation), but never
really was. It made it difficult to pass character vectors as single
entities where that was desired. I.e., the new behaviour is a feature,
not a bug.

This leaves a generic problem with R programming: Given letters[1:3],
how to generate

tkinsert(listio, "insert", 'end', letters[1], letters[2], letters[3])

Probably the neatest way is

do.call("tkinsert", c(list(listio, "insert", "end"), as.list(letters[1:3]))) 

or maybe

i.end <- function(...) tkinsert(listio, 'insert', 'end', ...)
do.call("i.end", as.list(letters[1:3]))

An alternative is to use the listvariable techniques and maintain
things on the R side:

x <- tclVar()
listio <- tklistbox(tktoplevel() , listvariable=x)
tclObj(x) <- mylist <- c("foo","bar","baz")
mylist <- c(mylist,letters[1:3])
tclObj(x) <- mylist

   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-devel mailing list