Rev 15880 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{TclInterface}\title{Low-level Tcl/Tk Interface}%\alias{TclInterface}\alias{.Tcl}\alias{.Tcl.callback}\alias{.Tcl.args}\alias{$.tclvar}\alias{$<-.tclvar}\alias{tclvar}\alias{.Tk.ID}\alias{.Tk.newwin}\alias{.Tk.subwin}\alias{is.tkwin}\alias{tkdestroy}\alias{.TkWin}\alias{.TkRoot}\alias{addTclPath}\alias{tclRequire}\description{These functions and variables provide the basic glue between \R and theTcl interpreter and Tk GUI toolkit. Tkwindows may be represented via \R objects. Tcl variables can be accessedvia the pseudo-list \code{tclvar}.}\usage{.Tcl(...).Tcl.args(...).Tcl.callback(...).Tk.ID(win).Tk.newwin(ID).Tk.subwin(parent).TkWin.TkRoottkdestroy(win)is.tkwin(x)tclvar$nametclvar$name <- valueaddTclPath(path)tclRequire(package, warn = TRUE)}\arguments{\item{win}{a window structure}\item{x}{an object}\item{ID}{a window ID}\item{parent}{a window which becomes the parent of the resulting window}\item{path}{path to a directory containing Tcl packages}\item{package}{a Tcl package name}\item{warn}{logical. Warn if not found?}\item{...}{Additional arguments. See below.}% Actually, both .Tcl and .Tcl.callback take only a single argument;% I've forgotten why they were defined as ... arguments.}\details{Many of these functions are not intended for general use but are usedinternally by the commands that create and manipulate Tk widgets andTcl objects. At the lowest level \code{.Tcl} sends a command as a textstring to the Tcl interpreter and returns the result as a text string.\code{.Tcl.args} converts an R argument list of \code{tag=value} pairsto the Tcl \code{-option value} style, thusenabling a simple translation between the two languages. To send avalue with no preceding option flag to Tcl, just use an untaggedargument. In the rare case one needs an option with no subsequentvalue \code{tag=NULL} can be used. Most values are just converted tocharacter mode and inserted in the command string, but window objectsare passed using their ID string, and functions are passed via theresult of \code{.Tcl.callback}. Tags are converted to option flagssimply by prepending a \code{-}\code{.Tcl.callback} converts \R functions to Tcl command strings. Theargument must be a function closure. Thereturn value is something of the form \code{\{ R_call 0x408b94d4 \}} in whichthe hexadecimal number is the memory address of the function.\code{.Tcl.args} takes special precautions to ensure that the functionwill exist at that address by assigning the function into the relevantwindow environment (see below).Tk windows are represented as objects of class \code{tkwin} which arelists containing a \code{ID} field and an \code{env} field which isan \R environments, enclosed in the global environment. The value ofthe \code{ID} field is identical to the Tk window name. The \code{env}environment contains a \code{parent} variable and a \code{num.subwin}variable. If the window obtains subwindows and callbacks, they areadded as variables to the environment. \code{.TkRoot} is the topwindow with ID "."; this window is not displayed in order to avoidill effects of closing it via window manager controls. The\code{parent} variable is undefined for \code{.TkRoot}.\code{.Tk.ID} extracts the \code{ID} of a window,\code{.Tk.newwin} creates a new window environment with a given ID and\code{.Tk.subwin} creates a new window which is a subwindow of a givenparent window.\code{tkdestroy} destroys a window and also removes the reference to awindow from its parent.\code{is.tkwin} can be used to test whether a given object is a windowenvironment.\code{tclvar} is used to access Tcl variables. The Tcl variable nameis used as if it were a list element name in \code{tclvar}, but inreality \code{tclvar} is an object of class \code{tclvar} and \code{$}and \code{$<-} have special methods for that class.Tcl packages can be loaded with \code{tclRequire}; it may be necessaryto add the directory where they are found to the Tcl search path with\code{addTclPath}.}\note{ Strings containing unbalanced braces are currently not handledwell in many circumstances.}\seealso{\code{\link{TkWidgets}},\code{\link{TkCommands}},\code{\link{TkWidgetcmds}}.\code{\link{capabilities}("tcltk"}} to see if Tcl/Tk support wascompiled into this build of \R.#ifdef windows(It is possible to build with Tcl/Tk support but not be able to run it,if the DLLs are not available or \code{TCL_LIBRARY)} is not set.)#endif}\examples{\dontrun{## These cannot be run by example() but should be OK when pasted## into an interactive R session with the tcltk package loaded.Tcl("format \"\%s\\n\" \"Hello, World!\"")f <- function()"HI!".Tcl.callback(f).Tcl.args(text="Push!", command=f) # NB: Different addresstclvar$xyzzy <- 7913 ; .Tcl("set xyzzy").Tcl("set xyzzy 3917") ; tclvar$xyzzytop <- tktoplevel() # a Tk widget, see Tk-widgetsls(envir=top$env, all=TRUE)ls(envir=.TkRoot$env, all=TRUE)# .Tcl.args put a callback ref in here}}\keyword{ misc }