How to not fall into R's 'lazy evaluation trap'

后端 未结 4 948
执念已碎
执念已碎 2021-02-04 05:40

\"R passes promises, not values. The promise is forced when it is first evaluated, not when it is passed.\", see this answer by G. Grothendieck. Also see this question referring

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-04 06:11

    R has a function that helps safeguard against lazy evaluation, in situations like closure creation: forceAndCall().

    From the online R help documentation:

    forceAndCall is intended to help defining higher order functions like apply to behave more reasonably when the result returned by the function applied is a closure that captured its arguments.

提交回复
热议问题