From p.dalgaard at biostat.ku.dk  Thu Sep 25 09:22:46 2003
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard BSA)
Date: Thu Sep 25 10:23:52 2003
Subject: [Rd] tkinsert (PR#4289)
In-Reply-To: <200309250517.h8P5Hd0P019420@pubhealth.ku.dk>
References: <200309250517.h8P5Hd0P019420@pubhealth.ku.dk>
Message-ID: <x2d6dpqnta.fsf@biostat.ku.dk>

Mark.Bravington@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)
tkpack(listio)
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@biostat.ku.dk)             FAX: (+45) 35327907


[Rd] tkinsert (PR#4289)
Peter Dalgaard BSA