3 ms·
> as.tibble(cbind(x,y,z)) %>% na.omit() Why on earth would anyone write that instead of na.omit(as.tibble(cbind(x,y,z)))? Baffles me.
by lottin 9y ago
> as.tibble(cbind(x,y,z)) %>% na.omit()
Why on earth would anyone write that instead of na.omit(as.tibble(cbind(x,y,z)))? Baffles me.
- stared 9y ago...reading from left to right for starter? It's why I adore %>% as code gets reads as a sequence of step-by-step instructions, of one forcing a reader to constantly keep switching between left-to-right and right-to-left.
- tincholio 9y agoHi, author here. I just find it much more intuitive, like unix pipes, or Clojure's threading macros. Nested calls are more confusing to me. Though it should have probably been better as cbind(...) %>% as.tibble() %>% na.omit...
- tincholio 9y agoAnd it's fixed now
- confounded 9y agoAlternatively, x %>% bind_cols(y, z) %>% as.tibble() %>% na.omit() Makes the order of execution a little clearer (and uses more dplyr conventions). I still nest functions when working interactively with a REPL, but for code I'll have to reread in the future, the pipes save me much head scratching. Death to the pyramid of doom.
- tincholio 9y agoThat's indeed a nicer style
- minimaxir 9y agoFor emphasis, bind_cols is a dplyr function (meaning it gets the speed boost from using Rcpp, albeit not much difference when adding a few columns), while cbind is a base function which does not. dplyr nowadays obsoletes most of the basic building blocks of data frame construction, although they are hidden in the docs.
- minimaxir 9y agoSee previous discussion on the perks of dplyr/margittr piping: https://news.ycombinator.com/item?id=15119957 https://news.ycombinator.com/item?id=15119957