[R] Tcl/tk , question about the environment of the call

jw9@softhome.net jw9 at softhome.net
Wed May 29 20:15:20 CEST 2002


This is my simple code, my intention is to let the inner function browse the 
objects in the outer function. 

####################### 

tk1 <- function() {
	tk2 <- function() {
		inner <- 3
		list2 <- ls()
		#list objects in fuction tk2
		print("**** inner objects ****")
		print(list2)
		
		#list objects in fuction tk1
		list_parent <- ls(parent.frame())
		print("**** outer objects ****")
		print(list_parent)
	}
	tt <- tktoplevel()
	outer <- 1
	tkpack(tkbutton(tt,text="push",command=tk2()))
	tk2()
}
####################### 

there's a call of tk2 inside tk1, so when I run tk1(), it gives the output I 
expected: 

[1] "**** inner objects ****"
[1] "inner"
[1] "**** outer objects ****"
[1] "outer" "tk2"   "tt" 

but when I clicked the push button, which also bind to the tk2 function, the 
result is different from that from the first tk2() call: 

> [1] "**** inner objects ****"
[1] "inner"
[1] "**** outer objects ****"
character(0) 

I am not sure in which part I made the mistake,  Any help or suggestions 
will be highly appreciated. Thanks!
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list