Live data from Hacker News

An opinionated view of the Tidyverse “dialect” of the R language

github.com

141–150 of 156 posts

Re: An opinionated view of the Tidyverse “dialect” of the R language

#141

Earlier quoted context omitted.

His critique is more about the impact of the full ecosystem effect of the Tidyverse, not what you are referring to, which is just the dplyr semantics. The Tidyverse demands that it's many related packages use tidy data principles and lock users into that approach, which differs from base-R. Much of this discussion is really just a debate about dplyr and magrittr rather than the fragmentation that the broader tidyvers…

I think any one making the point of speed of development have seriously missed the boat. Lets be real: tibbles suck. Once you get the hang of data.table syntax for matrix operations, its superiority becomes impeccably clear. I run a data science group a large geospatial company and we develop day in and day out in R and python. We've purged tidyverse as much as possible from all of our code base. We've moved complete…

Let’s keep the discussion civil please. People have legitimately different needs, and just because a package isn’t well suited to your needs doesn’t mean that it doesn’t help people with different backgrounds and goals.

Re: An opinionated view of the Tidyverse “dialect” of the R language

#142
post #98

Earlier quoted context omitted.

map() in purrr is functionally equivalent to lapply(). If you can do something in lapply, you can do it with map.

Right, which is why my example used its cousin, apply, instead of lapply. apply over the row margins of a data frame does not have an equivalent in tidyverse.

Beware that apply() coerces data frames to matrices, which is time consuming and forces all columns to have the same type.

Re: An opinionated view of the Tidyverse “dialect” of the R language

#143
post #138
post #137

Earlier quoted context omitted.

My point is that sometimes you don't have a single "thread" of calculation. Putting rbind into a pipe like you did is somewhat artificial (broken symmetry) and doesn't work so well if there is some pre-processing before the merge and some post-processing after the merge (or if we have two or more essentially different arguments in a function that need some preprocessing). You may say that having multiple pipes, one m…

I don’t think anyone is arguing that the pipe should be the -only- form of composition. Just that it’s a useful form when you have a linear sequence of transformations. Sometimes it’s useful to force something close to being linear into a linear form for consistency, but typically you would switch to an alternate form of composition, typically assigning to intermediate variables. It’s easy to find examples of using t…

I was actually excited about pipes when they were introduced but in the end I'm pretty happy writing and debugging "unreadable" code.

I had a similar experience with Lisp syntax: Clojure's threading macros seem a neat idea but I do actually prefer old-style nesting of function calls.

Maybe my R journey is a bit atypical. I started learning R around the time you created reshape and ggplot and used them extensively. But as the "tidyverse" thing has evolved I have found myself more attracted to "base" R as I've become more familiar with its data structures and functionalities.

Re: An opinionated view of the Tidyverse “dialect” of the R language

#144
post #44

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…

Another underestimated advantage is the guarantee that dplyr functions that manipulates a data frame, will always return a data frame.

Re: An opinionated view of the Tidyverse “dialect” of the R language

#145
post #80

Earlier quoted context omitted.

Can you provide an example of a problem that requires multiple tidyverse operations, but could be solved equally well using only lapply?

I run a large scale national survey. We download the data from our survey platform. Survey respondents are asked 100+ questions. The questions change week to week and so the column names are not consistent. We exclude respondents who appear to be cheating the system (rushing through questions, straight-lining, skipping almost every question, etc.) As part of our completion check, we want to do a row-wise map of the d…

You are right that tidy data is in a different form that many supplied tables are.

If I understand correctly, you want to know how many NA's there are in each column in a wide-form dataset (as opposed to a tidy dataset)

    # One line to make the data tidy.
    # The form of data will be 3 columns: id, question, answer, and no, we don't care what the columns are called, except for id.
    tidydf % gather("question", "answer", -id) 

    # one line to do your check
    tidydf %>% group_by(id) %>% summarise(n_NA = sum(is.na(answer)))
Tidyverse is highly opinionated about its data structure, and it is one of its limiting factors, as it basically treats every dataset as a sparse dataset. This actually fits very well with your data, as a datapoint is not a fixed questionnaire, but rather a datapoint is a respondents answer to a question (as questionnaires vary in questions, a tall table layout is quite fitting).

From there on you have to think in groups and summaries, unless you wanna fight the library.

Tidyverse is an 80% datascience solution. It solves what you need 80% of the time really, really well, and the last 20% you either have to fall back to base R or really torture dplyr.

Re: An opinionated view of the Tidyverse “dialect” of the R language

#146
post #143
post #138

Earlier quoted context omitted.

I don’t think anyone is arguing that the pipe should be the -only- form of composition. Just that it’s a useful form when you have a linear sequence of transformations. Sometimes it’s useful to force something close to being linear into a linear form for consistency, but typically you would switch to an alternate form of composition, typically assigning to intermediate variables. It’s easy to find examples of using t…

I was actually excited about pipes when they were introduced but in the end I'm pretty happy writing and debugging "unreadable" code. I had a similar experience with Lisp syntax: Clojure's threading macros seem a neat idea but I do actually prefer old-style nesting of function calls. Maybe my R journey is a bit atypical. I started learning R around the time you created reshape and ggplot and used them extensively. Bu…

A lot depends on what you’re doing. Most of the time, when I’m not doing data analysis, I don’t find pipes to be that useful so I don’t use them.

Re: An opinionated view of the Tidyverse “dialect” of the R language

#147
post #134
post #131

Earlier quoted context omitted.

If you find that the example above is not "human readable" then the following code will make your head explode because it cannot be transformed into a pipe representation (or at least it's not so straightforward): the_data x), variable_c = variable_a/variable_b)

Maybe consider: the_data % rbind(read.csv('/path/to/data/file2.csv')) %>% filter(variable_a > x) %>% mutate(variable_c = variable_a/variable_b) You've thrown out a few variations on a theme here, but I'm not sure where you are trying to angle towards. There are a lot of ways to format code, and I can't tell you what works best for you. But this isn't shaking the paradigm of having an initial block of data (here separ…

For the record, the original example is from the homepage of magrittr (I found it here https://www.fromthebottomoftheheap.net/2015/06/03/my-aversio...) and I'm not trying to angle towards anywhere. I only wanted to point out that the version with a sequence of assignments is not so painful to read (to me) and even the nested version is readable and has some advantages. Not that anyone cares, but I think I would have written something like:

  df  x]
  df$variable_c 
or maybe:

  df  x)
  df[,”variable_c”] 
Whether you think these are badly written pipes or not pipes at all, I don't care. It's good enough for me.

Re: An opinionated view of the Tidyverse “dialect” of the R language

#148
post #99

Earlier quoted context omitted.

> This is particularly true of Scheme which foregoes much of the dynamic quality of Common Lisp The idea of even the standard Common Lisp is that both is possible: a static Common Lisp and a dynamic Common Lisp, even within the same application in different sections of the program. Common Lisp allows hints to the compiler to remove various features (like fully generic code being reduced to type specific code), it all…

Its definitely the idea. I know it works well enough for a lot of people, but for me, I'm happy to just give up on the dynamic behavior in favor of a simpler universe. The last thing I want to be thinking about is whether my compiler needs a "hint" that something can be stack allocated, for instance. That is their business, not mine.

Common Lisp as a language standard makes no commitment to the smartness of a compiler. If a certain compiler can figure out things, great, but some compilers might be dumb by design (for example to be fast for interactive use). That's left to implementations.

Re: An opinionated view of the Tidyverse “dialect” of the R language

#149
post #8

One reason dplyr was promoted is that you can connect to different server backend like sparkr, sql etc, which is the enterprise direction RStudio aiming at. In the other hand, data.table is your friend when you are using your own machine. With more and more memory and cpu power available, its benefits are actually increasing. I have been using data.table from almost day one, it does worth more recognition. The syntax…

If my university uses Enterprise RStutio on grid it is better to stick with tidyverse rather than data.table?

It doesn't make a difference. Rstudio's products aren't integrated with their libraries in particular.

Re: An opinionated view of the Tidyverse “dialect” of the R language

#150
post #140

Earlier quoted context omitted.

I 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

After 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 o…

Yeah, that's a valid point. And it took me a couple years to internalize these differences -- mostly by being burned on numerous occasions. Base R has a lot of idiosyncrasies and they have to be memorized, unfortunately.

I develop R packages for my colleagues and so I stick to Base R whenever possible. I don't want my packages depending on the tidyverse at all. But for EDA, I am agnostic about what my colleagues do. They should use the tools that stay out of the way and let them get their hands around the dataset intuitively. For me that's Base R, for others it's data.table or tidyverse.

Post reply on HN