[R] Tcl Tk table
James Wettenhall
wettenhall at wehi.edu.au
Mon Apr 26 15:17:21 CEST 2004
On 26 Apr 2004, Peter Dalgaard wrote:
> > As noted previously, in R >= 1.8.0 tclArray() is a better way
> > to handle Tcl arrays.
>
> Doesn't really help with tagging though (or does it?)
Not that I know of. I just thought I'd point out to anyone
still using .Tcl("set tclarray...") or whatever, that while they
may have copied that from one of my examples previously, now I
would recommend using the official tclArray() interface in the
tcltk package which does some nice stuff that the user shouldn't
have to worry about (see tclArray() and tclVar() functions).
> BTW, .Tk.ID sneaked in again... I wonder what is the cleanest way of
> doing this stuff. This works (inserting "list" to compensate for
> absence of tktable):
Oops. Sorry about the unnecessary .Tk.ID()
It is very nice having all of the wrapper functions to take
care of quoting-hell etc. etc. but at the moment there are a
lot more Tcl/Tk examples and documentation in pure Tcl/Tk than
R-Tcl/Tk, so often, I firstly ask "How would I do this in
pure Tcl/Tk?" and then I translate, so that's why using the
.Tk.ID() function feels quite natural to me.
If I teach myself to avoid .Tk.ID() as much as possible in
order to improve my R-Tcl/Tk coding style, should I also try to
avoid tclvalue() as much as possible? (I'm pretty sure the
answer is "No".) They seem similar in that they both convert
a Tcl/Tk object into a string, but while .Tk.ID() is
unnecessary/wrong for the example in this thread, tclvalue()
is still necessary for this:
foo <- tclVar("one two")
tkmessageBox(message=foo) # Doesn't work :(
tkmessageBox(message=tclvalue(foo)) # Does work :)
So this analogy is my current excuse for mistakenly
using .Tk.ID() when it isn't needed.
Sometimes I get an error from tcl which I don't really
understand, and the first question I ask myself is "What
would the Tcl/Tk command look like if I had written it in pure
Tcl/Tk?" or more precisely, "What is the Tcl/Tk command being
sent to Tcl/Tk from R?"
It seems that this second question was slightly easier to answer
with the old R-Tcl/Tk interface, where you could use .Tcl.args()
etc. .Tcl.args.objv() is very similar but it doesn't look as
much like a Tcl command as it did with .Tcl.args(), so if you
wanted to ask a question to someone who only speaks pure Tcl/Tk
and just gave them the output of .Tcl.args.objv(), they might be
a little confused (see below). And if you just looked at the
tkcmd() function's R code to try to work out what the
corresponding Tcl/Tk command would be for an R-Tcl/Tk command,
you may at first think that there's no way to tell within
R, because .Tcl.objv() calls an external C function. But in
fact .Tcl.args.objv() actually tells you quite a lot:
> .Tcl.args.objv("wm","title",tt,"The Title")
[[1]]
<Tcl> wm
[[2]]
<Tcl> title
[[3]]
<Tcl> .3
[[4]]
<Tcl> The Title
Of course, a nicer solution than making it easy to find the
corresponding Tcl/Tk command so you can go running to the Tcl/Tk
community for help, is to have the R-Tcl/Tk user base contribute
to its documentation so eventually it is better than the pure
Tcl/Tk documentation or the Perl/Tk documentation!!!
Where should we start? What can I do?
Regards,
James
More information about the R-help
mailing list