R Tcl/Tk recipes

R Tcl/Tk recipes

James Wettenhall & Philippe Grosjean bio photo By James Wettenhall & Philippe Grosjean

PDF version

Tcl (Tool Command Language) is a dynamic scripting language that is easily embedded in other applications. Tk is a cross-platform graphical user interface (GUI) toolkit. Both are useable from within R thanks to the tcltk package. The Tk toolkit is a decent one, but not the most feature-rich. However, the big advantage of Tcl/Tk is its wide availability in all platforms supported by R: the package is maintained by the R Core Team, and it is shipped with R itself. To check if Tcl/Tk is available, use the command capabilities("tcltk").

The tcltk2 package is also available from CRAN. It offers additional possibilities and more widgets. These recipes show how to use both the tcltk and the tcltk2 packages with R to build a GUI, or to use other potentials of Tcl.

Basic techniques

  • Basic widgets

  • Additional widgets

  • Advanced tcltk coding


  • Other sources of R tcltk help/examples

    1. Run help.start() in R to get HTML help, then click on Packages, then click on tcltk or tcltk2.

    2. Read the ActiveTcl help and learn how to convert Tcl options to R arguments, e.g.

      -background white

      becomes in R

      background = "white"

    3. Read Peter Dalgaard’s articles in Rnews : Rnews 2001, Vol. 3 and Rnews 2002, Vol. 3.

    4. Study the demos in the R tcltk package, e.g. tkdensity and tkttest.

    5. Read and participate in R-Help and other R mailing lists.

    6. Search the web for Tcl/Tk examples, and don’t ignore them completely if they use a language other than R, e.g. Perl or Python. A lot can be learned from these examples.

    References