[R] R and tcltk Package

Roderick hruodr @end|ng |rom gm@||@com
Tue Mar 15 20:27:13 CET 2022


Dear Sirs,

I began not long ago to learn R. Now I want to understand the
tcltk binding. I have very elementary questions that are not
clear from help(TclInterface).

Let us say, I do

> library(tcltk)
> .Tcl("set k 2")
<Tcl> 2

How do I access the variable k from R?
And how do I access R variables from tcl?

I read that tclVar() creates a new Tcl variable. Well, the following
example shows that this is not 100% true:

> a<-tclVar()
> as.character(a)
[1] "::RTcl1"
> .Tcl("set ::RTcl2 5")
<Tcl> 5
> .Tcl("set ::RTcl2")
<Tcl> 5
> b<-tclVar()
> .Tcl("set ::RTcl2")
<Tcl>
> as.character(b)
[1] "::RTcl2"

Since ::RTcl2 existed, b<-tclVar() should have created something
different and new, perhaps ::RTcl3.

Can I at least be sure that all variables generated by tclVar()
and tclArray() are of the form ::RTcl2N ?

And what are these callbacks, are they functions callable from Tcl?
The following does not work:

> f<-function() return(7)
> f()
[1] 7
> .Tcl.args(f)
[1] " { R_call 0x80e29e2e0 }"
> .Tcl(.Tcl.args(f))
Error in structure(.External(.C_dotTcl, ...), class = "tclObj") :
   [tcl] invalid command name " R_call 0x80e29e2e0 ".

Is there a more detailed guide than help(TclInterface)?

Thanks for any hint
Rodrigo



More information about the R-help mailing list