tidyverse / tidyverse.org

Source of tidyverse.org
https://tidyverse.org
Creative Commons Attribution Share Alike 4.0 International
191 stars 113 forks source link

tidyverse style compliance #489

Open lorenzwalthert opened 3 years ago

lorenzwalthert commented 3 years ago

I have noted a few times that code in articles does not correspond to the tidyverse style guide. I can't find any note on the style guide to use in the README.md either. I think we could improve on coding style in various ways:

hadley commented 3 years ago

Do you have any examples?

lorenzwalthert commented 3 years ago

I applied styler to the 2020 posts in https://github.com/lorenzwalthert/tidyverse.org/commit/d861f38d6440c69314abe350726df768d5d0b622, but the diff is not so useful since it mostly contains end of line space formatting and other artifacts.

Reviewing the last 18 posts superficially manually, here is what I found:

I think the most prominent example is with indention and line breaks:

model <- 
  nearest_neighbor(neighbors = tune(), weight_func = tune(), 
                   dist_power = tune()

Or things like


glmnet_grid <- tidyr::crossing(penalty = 10^seq(-6, -1, length.out = 20), mixture = c(0.05, 
    0.2, 0.4, 0.6, 0.8, 1)) 

in https://www.tidyverse.org/blog/2020/09/usemodels-0-0-1/

Then, there is minor ones like

1 %>% identity() %>% invisible() %>% identity()

in https://www.tidyverse.org/blog/2020/11/magrittr-2-0-is-here/ and others.

Obviously the world has bigger problems, but implementing one of my suggestions seem a reasonable cost/benefit ratio. In addition, when authors know styling is taken care of, they can spend their attention on the text and what the code does, not what it looks like.