4

Perhaps I'm missing something obvious.

In R, TRUE && NA evalues to NA. This doesn't make sense to me, because && should evaluate left to right, and stop as soon as one of its conditions is true.

flodel
  • 87,577
  • 21
  • 185
  • 223
Daniel Kessler
  • 1,172
  • 17
  • 21

1 Answers1

21

This doesn't make sense to me, because && should evaluate left to right, and stop as soon as one of its conditions is true.

This is wrong. You are mixing up && with ||:

  • TRUE && FALSE gives FALSE
    • && requires both conditions to be TRUE
    • && will short-circuit on FALSE
  • TRUE || FALSE gives TRUE
    • || requires a single condition to be TRUE
    • || will short-circuit on TRUE

Also,

TRUE || NA 

gives

TRUE
csgillespie
  • 59,189
  • 14
  • 150
  • 185