[R] charge a vector with variables and to use as variable in a checkbutton?

Dirk Eddelbuettel edd at debian.org
Tue Sep 9 17:44:20 CEST 2003


On Tue, Sep 09, 2003 at 12:10:06PM -0300, solares at unsl.edu.ar wrote:
> hello, how i cant to charge in form dynamic a checkbutton, try to do it 
> with a vector be charged automaticamente but not
> works, for example
[...]
> while (i<=j){ 
>  b[i]<-tkcheckbutton(f,text="b[i]",variable="b[i]",relief="raised")
> #how b[i] is the same "variable" all the time for checkbutton
>  tkpack(b[i])
>  i<-i+1
> }

You may want to re-read some of the available code examples. What you did is
fundamentally broken -- you do not pass strings with variables names inside.

You need to define some variables via the tclVar() function, and you can
access the values of those variables in non-tcltk expressions with tclvalue().

What you want it probably close to this -- it uses menubuttons rather than
checkbuttons but is the closest example I had hanging around here:


    color <- tclVar("blue")
    long.color <- tclVar(paste("Status is", tclvalue(color)))
    for (i in c("red", "green", "blue"))
      tkadd(m, "radio", label=i, variable=color, value=i,
            command=function(){
              cat("Background is", tclvalue(color), "\n")
              tclvalue(long.color) <- paste("Status is", tclvalue(color))
            })
			  
Hth, Dirk

-- 
Those are my principles, and if you don't like them... well, I have others.
                                                -- Groucho Marx




More information about the R-help mailing list