From ggrothendieck at gmail.com  Thu Aug 12 21:02:52 2010
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Thu, 12 Aug 2010 15:02:52 -0400
Subject: [Rd] accessing tcl variables within R and tcl
In-Reply-To: <4C643A0A.3060901@waddell.ch>
References: <4C643A0A.3060901@waddell.ch>
Message-ID: <AANLkTimSCSo3GcFJ+JxkuAo9CHEYrYBJ+FTP+GhzyqN_@mail.gmail.com>

On Thu, Aug 12, 2010 at 2:14 PM, Adrian Waddell <ml_a at waddell.ch> wrote:
> Dear R users,
>
> I have some troubles with dealing with tclObj objects. I try to explain
> it with a toy example:
>
> Say I define the following tcl procedure which just prints out each list
> element
>
> library(tcltk)
> .Tcl('proc test {myList} {
> ? ?foreach i $myList {
> ? ? ?puts stdout ?$i
> ? ?}
> }')
>
> and I call it with:
>
>> tcl('test',letters[1:5]) ? ?# Works as expected
>
> Now say I define a tcl variable first:
>
>> a <- tclVar("")
>> tclObj(a) <- as.tclObj(letters[1:5])
>
>> tcl('set',a) ?# output list
>
> However
>
>> tcl('test',a) # does not work as expected, returns the variable name
>
> Why not? In fact, how do get the name of the "a" list in tcl (something
> like RTcl...) so I could use it as follows
>> .Tcl('test $RTcl1') #works
>
> Loops are much quicker in tcl than in R, hence I try to do some
> computations in tcl and not via wrapper function in R. I therefore need
> a way to easily access tcl variables from within R and tcl.
>

Try this:

tcl("test", tclvalue(a))



[Rd] accessing tcl variables within R and tcl
Gabor Grothendieck