Use of ! (or any logical operator) with %>% (magrittr) produces unexpected output

前端 未结 3 1932
猫巷女王i
猫巷女王i 2021-01-18 14:28

I have run across a situation where %>% produces very surprising output when combined with !. Consider the following code:

x <         


        
3条回答
  •  时光取名叫无心
    2021-01-18 14:30

    I suspect that it's an order of operations issue:

    !is.na(x) %>% sum
    

    is evaluating to

    !(is.na(x) %>% sum)
    

    Which is equivalent to TRUE

提交回复
热议问题