4 ms·
From personal experience, I learned R during college as a part of my stats courses, before tidyverse even existed. After doing a few personal projects using ba
by minimaxir 7y ago
From personal experience, I learned R during college as a part of my stats courses, before tidyverse even existed.
After doing a few personal projects using base R with complex manipulations, I would have quit using R entirely if it were not for tidyverse/dplyr.
I'm a pragmatic software engineer: I prefer to get a data analysis job as fast as necessary, and IMO there isn't much merit in making things more complicated by using base R just for the sake of base R. It's definitely not faster, both in cognitive load and in speed. In my data science work there hasn't been a single case where I've needed to fall back to base R, or wanted to.
Pipes are being undersold here: the examples only show a single piped action, whereas pipes shine when you have to do 5+ operations in a single manipulation (I've seen base R code that does that by just having a lot of redundant df assignments and it's a pain to read).
- tvladeck 7y ago> a lot of redundant df assignments either that or a profusion of variables going into your global environment, which is a massive pain to track!
- kgwgk 7y agoThis also looks painful: https://community.rstudio.com/t/magrittr-inside-a-package/2033 https://community.rstudio.com/t/magrittr-inside-a-package/20...
- minimaxir 7y agoThat's an interesting caveat with pipes/magrittr (I didn't know of it), although it's out of scope of this debate since this discussion is just about how tidyverse uses pipes. In my experience if there's a package that's required in a script/R Notebook outside of tidyverse, I just import the entire library at the start of the file Python-style (to make the dependency obvious), which would avoid this issue.
- kgwgk 7y agoIf you claim that something like the_data <- read.csv('/path/to/data/file.csv') the_data <- subset(the_data, variable_a > x) the_data <- transform(the_data, variable_c = variable_a/variable_b) the_data <- head(the_data, 100) is a pain to read compared to the_data <- read.csv('/path/to/data/file.csv') %>% subset(variable_a > x) %>% transform(variable_c = variable_a/variable_b) %>% head(100) I thinks it’s fair to mention how by making things more complicated by using pipes you expose yourself to other issues. (In my opinion the first variant is not less readable, and it has the advantage of allowing any of the operations to be removed by commenting the corresponding line, while in the second case to remove the last operation you also need to remove the piping operator in the preceding line.) [Edit: I’m not sure I understand your “out of scope” remark. You don’t mean that magrittr is outside of tidyverse, do you?]
- cwyers 7y agoBecause the pipes are at the end of the line, you can comment out a line and it will still work fine unless you're removing the last line of the chain.
- kgwgk 7y agoThat’s precisely what I said.
- roenxi 7y agoThey are roughly equivalent to read; but the reason for that is that the first code sample is clearly someone unwinding something that they are conceptualising as a piped statement. If you aren't conceptualising the code as an unwound pipe, you'd have to actually inspect the code and think about what each function argument means rather than being confident it is a set of chained transforms as you can be by glancing and seeing a %>%. I'm a bit suspicious about that coincidence - after I met the pipe operator, a lot of my code looks like that. Before I met the pipe operator, not very much of my code looked like that. As long as people are thinking in pipes then they can choose if they value making commenting code cheap vs making reading/typing code cheap. But it is quite important that beginners are introduced to pipes as a concept as they learn R. The semantics are critical, using the syntax is optional.
- phonebucket 7y agoWith regards to the usefulness of piping with dplyr: the post does express its admiration for data.table as the alternative for dplyr. In data.table, chaining operations together is standard and as simple as a set of brackets to contain the next operation. Both are preferable to pandas though (joke not troll).
- bsg75 7y agoThere are nuances that to me make R data frames, especially with Magrittr, simpler to work with over Pandas. Pandas indexing always seems to get in the way. I have been using Python a lot longer than R, but the Pandas syntax is taking longer to internalize. Maybe it's just me?
- wodenokoto 7y agoNo. Pandas is a powerful tool, but a poor api / user interface.
- finebalance 7y agoPandas grouping and slicing is, imo, significantly worse than R. And I so despise those multiindexes.
- phonebucket 7y agoFor those R users who aren't quite enjoying Pandas so much, I enjoyed the following blog post: https://stmorse.github.io/journal/tidyverse-style-pandas.html https://stmorse.github.io/journal/tidyverse-style-pandas.htm...
- c06n 7y agoI use piping in combination with data.table all the time. It works simply like this: my_dt %>% .[i, j, by] It's a powerful combination. Fast, very readable, extremely versatile.