I run the following code
sapply( 0:3, function(x){ls(envir = sys.frame(x))} )
And get the following result
[[1]]
[1] "mat" "mat_inverse"
[[2]]
[1] "FUN" "simplify" "USE.NAMES" "X"
[[3]]
[1] "FUN" "X"
[[4]]
[1] "x"
It seems like it lists all the objects in the current enclosing environment; I do have mat and mat_inverse as two variables. But I am not sure what it returns for [[2]], [[3]], [[4]]. Is there a way to debug this code to track what this code does? Especially the following part:
envir = sys.frame(x)
is very confusing to me.