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

后端 未结 4 955
执念已碎
执念已碎 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:13

    As others pointed out, this might not be the best style of programming in R. But, one simple option is to just get into the habit of forcing everything. If you do this, realize you don't need to actually call force, just evaluating the symbol will do it. To make it less ugly, you could make it a practice to start functions like this:

    myfun<-function(x,y,z){
       x;y;z;
       ## code
    }
    

提交回复
热议问题