[R] R and TK Error "can't find objects"

Immanuel Seeger jimmy-seeger at web.de
Wed Aug 11 12:40:49 CEST 2010


Dear R People,
I’m trying to link R and TK. I’m using R 2.11.1 with Tinn-R 1.17.2.4.
For simple examples like the following one it’s working (see the
initiation of the variables, the handler and the link to the function
which multiply Zahl, Exponent and Factor) : 

require(tcltk)
Ergebnis<-tclVar(c(0,0,0,0,0,0)) 
Zahl<-tclVar(c(0,0,1,1,1,0))
Exponent<-tclVar(c(1,1,1,1,1,1))
Factor<-tclVar(2)

handler.Quadrieren<-function() {
tkconfigure(e,
textvariable=tclVar(test2(as.numeric(tclObj(Zahl)),as.numeric(tclObj(Exp
onent)),as.numeric(tclvalue(Faktor)))))
}


test2 <- local({source("C:/.../Tk_einfach.R", local = TRUE)
        environment(Quadrieren) <- .GlobalEnv
        Quadrieren })




Now I want to do the same with my more difficult work:


#Variable initiation and handler-functions in the GUI(TK)-file:



AnzKnd<-tclVar(ANZK)
Besuchshäufigkeitakt<-tclVar(c(4,8,2,4,6))             
ZK<-tclVar(c(3,2,4,1,2))   
durch<-tclVar(seq(length=ANZK,from=1,by=0))    
Seins<-tclVar(seq(length=ANZK,from=0,by=0))   
Szwei<-tclVar(c(33,4,6,12,55))                
Sdrei<-tclVar(c(55,48,10,20,80))              
Svier<-tclVar(c(61,53,13,24,94))                                     
Sfünf<-tclVar(c(62,54,14,27,100))                                    
Zeitb<-tclVar(52)                     
maxBes<-tclVar(10)

handler.plan<-function() {
              tkconfigure(planErgebnis,
textvariable=tclVar(test2(as.numeric(tclvalue(AnzKnd)),as.numeric(tclval
ue(maxBes)),as.numeric(tclObj(Besuchshäufigkeitakt)),as.numeric(tclObj(Z
K)),as.numeric(tclObj(durch)),as.numeric(tclObj(Seins)),as.numeric(tclOb
j(Szwei)),as.numeric(tclObj(Sdrei)),as.numeric(tclObj(Svier)),as.numeric
(tclObj(Sfünf)),as.numeric(tclvalue(Zeitb)))))
                        }


test2 <- local({source("C:/.../funktion.R", local = TRUE)
         environment(plan) <- .GlobalEnv
         plan })


The head of the file/ function in "C:/.../funktion.R" looks like this:

plan<-function(AnzK,maxBesuche,Besuchshäufigkeitaktuell,ZpK,d,ZER,S2,S3,
S4,SAT,Zeitbudget){ 
...
}

When I'm starting the function in "C:/.../funktion.R"  (with the
variables initiated like above, but  without tclVar) it's running.
Also when I'm opening it from GUI but re-initiate the variables in the
funktion.R!

So I'm thinking that there is some problem with the initiation/transfer
of the variables from the GUI to the "C:/.../funktion.R"!
Maybe as.numeric(tclObj(...)) is not the right one? But then I don't
understand why it's working in the easier example above.


The error is: 
Error in plan(AnzK, maxBesuche, Besuchshäufigkeitaktuell, ZpK, d,  : 
  Object 'Besuchshäufigkeitaktuell' not found



Thanks!

Immanuel Seeger



More information about the R-help mailing list