[R] tcltk: I guess I am starting to get it

Alberto Monteiro albmont at centroin.com.br
Thu Oct 18 14:18:24 CEST 2007


I found a great site with many Perl/tk examples (it's in German):

http://gd.tuwien.ac.at/languages/perl/Hajji-Perlkurs/part4/tkperl.html

It's quite simple to convert these examples to R's tcltk. One
that gave me some trouble was:

# (please open the file to get the context)
# (...)
# a checkbutton with dynamic text
$now = localtime(time);
$c2 = $mw->Checkbutton(-textvariable => \$now,
                       -anchor       => "w",
                       -command      => sub { $now = localtime(time) },
                       -state        => "active",
                       -variable     => \$c2_value,
                       -onvalue      => $now,
                       -offvalue     => "No time");
# (...)

which became:

library(tcltk)

# first of all, create a main window 
mw <- tktoplevel()

# (...)
now <- tclVar(date())  # this is different from Perl/Tk
c2 <- tkcheckbutton(mw,
  textvariable = now,
  anchor = "w", 
  command = function() { tclvalue(now) <- date() },  # this is different 
from Perl/Tk
  state = "active", 
  variable = "c2_value", 
  onvalue = now, 
  offvalue = "No time")
# (...)

# display everything 
# (...)
tkpack(c2, anchor = 'w', fill = 'x')
# (...)
# enter main event collecting loop - necessary in perl but not in R

I tried to contact the author for permissions to translate, adapt
and post the examples to the RWiki, but without success :-(

Alberto Monteiro



More information about the R-help mailing list