Here I'm attempting to define a closure that contains a function which can be invoked :
myFirstClosure <- function (){
var1 = 1;
f1 <- function() {
var1
}
}
m <- myFirstClosure()
m.f1()
Error is returned : Error: could not find function "m.f1"
Why is the inner scoped function f1
not accessible as I have defined the outer scoped function myFirstClosure
?
Update :
Is it meaningless to invoke closures like :
myFirstClosure <- function (){
var1 = 1;
var2 = 0;
f1 <- function() {
var1
}
f2 <- function() {
var2
}
}
As f1
and f2
cannot be invoked independently ?