Advanced
R
Q86 / 100
What does "force()" do when used inside a closure-generating function, e.g. in a loop creating multiple functions?
Correct! Well done.
Incorrect.
The correct answer is B) It forces immediate evaluation of a lazily-evaluated argument/variable, preventing bugs where closures capture a variable's final value instead of its value at creation time
B
Correct Answer
It forces immediate evaluation of a lazily-evaluated argument/variable, preventing bugs where closures capture a variable's final value instead of its value at creation time
Explanation
force(x) simply evaluates x, which is used to "lock in" the current value of a variable used in a closure due to R's lazy evaluation, avoiding common loop-variable-capture bugs.
Progress
86/100