The questions relate to the call stack section in the lesson Creating Functions.
The two questions probe understanding of how variables are used across environments in R
After running the following code, what will R return (answer without running)?
a<-10
b<-20
function1<-function(){
a<-1
b<-2
c(a,b)
}
c(function1(),a,b)
After running the following code, what will R return (answer without running)?
rm(a,b)
a<-10
b<-20
function2<-function(){
a<-1
c(a,b)
}
c(function2(),a,b)
This will test the understanding of the function first looking in its own environment for variables
This answer is a red herring using the previous question - if the student has not noticed b was not defined in the new function, they will choose this
This tests the students understanding of how R searches for variables - if they dont understand it goes up in environments, they will choose this
This is the correct answer.