4 ms·
Why? Seems to simple. I normally go straight for drop=FALSE the most evil default issue of the language.
by Hansi 12y ago
Why? Seems to simple. I normally go straight for drop=FALSE the most evil default issue of the language.
- jghn 12y agoAgreed. There are many WTF things I can think of in R, this is absolutely not one of them.
- johnmyleswhite 12y agoMy experience asking people about that snippet is that very few people can correctly predict the results of that function without actually executing the code. What interests me about the question is that many people's mental model of how R programs are evaluated is often too vague to enable them to produce sharp predictions about program behavior prior to executing code.
- RA_Fisher 12y agoThis is funny because I was heavily skeptical yet completely reversed my opinion within 10 minutes. I correctly predicted the results, but I program R professionally. Then I asked my partner who's a non-programmer to read the snippet and her prediction was that the program would stop. That led me to reflect back on your statement. I think the key word is "sharp". I correctly predicted the result, but that's only because I trust lazy-eval heavily. Even then, it's hard to really cement trust in lazy-eval (for me) as it's difficult to mentally map. That's not exactly sharp after all!
- jghn 12y ago"but I program R professionally" To be fair to JMW, I used to as well - and perhaps more importantly I was writing end user software in R and not doing my own data wrangling.
- jghn 12y agoMy first answer was correct, although i'll admit to having run the snippet afterwards as I figured there was some trick in there that I couldn't see.
- johnmyleswhite 12y agoI didn't mean to imply I thought you would guess the wrong answer, but rather that most R users do not understand delayed evaluation well enough to understand how it will impact their code. Sorry if my comment seemed rude.
- jghn 12y agoI didn't find it rude, I just have trouble seeing it as a snippet which would really cause confusion. If you have seen people get confused by it though, I suppose it is.
- coldtea 12y ago>My experience asking people about that snippet is that very few people can correctly predict the results of that function without actually executing the code. Which is still not any serious barrier in using R succesfully.
- stewbrew 12y agoLazy evaluation in R isn't that difficult to grasp once you accept the fact and don't superimpose an evaluation model dominant in most other languages. It turns out, this kind of lazy evaluation can actually be quite useful.