3 ms·
He is glossing over the major issue with base R, which is its tendancy to switch data types in a way that appears random to new users. As an undergrad I spent n
by roenxi 7y ago
He is glossing over the major issue with base R, which is its tendancy to switch data types in a way that appears random to new users. As an undergrad I spent nights literally on the verge of tears debugging R code where the types had been mucked up by R's bizarre semantics. Claiming that data[foo] is the same as filter(data, foo) is not correct - the [] and [[]] operators have a lot of strange side effects depending on what argument is passed in. It is like saying map() and a for loop are the same because everything a map can do a for loop can do. That is true, but the single-mindedness of map is a major selling point because you know it is only going to do certain specific things. The issues here will disproportionately affect beginners who are likely to accidentally pass in the wrong thing - it needs to fail with an error or in a predictable way to best help them. Hadley's code fails sensibly.
One of the major innovations of the tibble package is that it puts the types of each column into the headings when it prints the table out. Dr. Matloff is grossly underestimating how painful it is for beginners to, eg, figure out when they are dealing with a column of strings vs a column of factors. If a beginner copies code to someone else for help, the other person can actually tell what types are involved! It is like magic compared to base R.
Given how ad-hoc the R community is and the paucity of people with programmer backgrounds, these minor usability improvements on controlling types are important. And anybody who cares about efficiency is using the wrong language.
EDIT Also, this comment that RStudio is bypassing an Open Source project's leadership - that is one fo the major features of open source. It is usually a healthy sign that the project leadership are lost in the weeds. I recall a situation with broad parallels in the history of GCC for example; it didn't kill the project although I believe a bad codebase died.
- nonbel 7y ago> "Dr. Matloff is grossly underestimating how painful it is for beginners to, eg, figure out when they are dealing with a column of strings vs a column of factors." This is just sapply(df, class)... Is this not found in R 101 material that beginners are likely to find?
- ACow_Adonis 7y agoPay no attention to the myriad of other apply functions hiding behind the curtain and the difficulty in remembering what each of them does and why you can't just use map, eh? :) So to answer your question, no, its not just simply that.
- ImaCake 7y agoLooking at the documentation; "sapply" is itself a wrapper for "lapply", and will do a number of different things depending on what arguments are passed into the function or not.
- nonbel 7y agoThere is nothing to remember to solve that problem besides the wrote memorization of sapply(df, class).
- Zelazny7 7y agoI use a simply device to keep these straight: - (l)apply: List apply always returns a list - (s)apply: simplify apply tries to return simplified result - (v)apply: verify apply checks the return type conforms to user supplied example - (m)apply: multiple apply applies FUN to multiple vectors - (r)apply: recursive apply is essentially a flatmap - apply : no device here, only use on matrices, never data.frames
- BoiledCabbage 7y agoLove it or hate it, it's pretty clear these fns had very little api design thought go into them. As much as I think people can lean too much on the concept, single responsibility principle would've gone a long way here.
- roenxi 7y agoAfter reading your explanation I still, as has been the case for years, don't understand what sapply or rapply does, and vapply sounds weird. That isn't going to change, because I'm just not going to use them or 'invest' the time in finding out what some statistician-of-yore's interpretation of a map is. Instead I'll stick to tidyverse map - returns a list. Or tidyverse map_[int/chr/dbl/etc, etc] if I want a vector of [int/chr/dbl/etc, etc]. That and the data frame manipulation verbs covers the most useful 80% of cases where *apply would otherwise be needed. If the base R team were implementing functions that way in the base, stats professors wouldn't need to complain about mass exoduses from base R.
- kgwgk 7y agoOr simply str(df) or summary(df)
- wodenokoto 7y agoAnother underestimated advantage is the guarantee that dplyr functions that manipulates a data frame, will always return a data frame.