0
1:11 %>% length() > 10

However, when I pipe it within a ifelse(), it evaluates it as if the condition must be applied per each element. Even the output is weird and illogical.

1:11 %>% ifelse(length(.) > 10,1)

At the same time,

ifelse(length(1:11) > 10,1)

works properly.

1 Answers1

0

I found the answer.

magrittr will always assume that the first argument of a function is ., even when not explicit. To drop this assumption:

1:11 %>% {ifelse(length(.) > 10,1)}

Gregor Thomas
  • 119,032
  • 17
  • 152
  • 277