Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tidyverse style compliance #489

Open
lorenzwalthert opened this issue Dec 8, 2020 · 2 comments
Open

tidyverse style compliance #489

lorenzwalthert opened this issue Dec 8, 2020 · 2 comments

Comments

@lorenzwalthert
Copy link
Contributor

lorenzwalthert commented Dec 8, 2020

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:

  • add a note in the README.md to style code before submission with {styler}.
  • recommend the use of tidy = 'styler' in R code chunks in .Rmd files or set in the first chunk for all subsequent R chunks, i.g. knitr::opts_chunk$set(tidy = 'styler').
  • integrate the above suggestion directly into the index.Rmd template that is created with hugodown::use_tidy_post("short-name") (not sure the issue should be transferred to the {hugodown} repo then).
@hadley
Copy link
Member

hadley commented Feb 20, 2021

Do you have any examples?

@lorenzwalthert
Copy link
Contributor Author

lorenzwalthert commented Feb 20, 2021

I applied styler to the 2020 posts in lorenzwalthert@d861f38, 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()
wide_reviews <- tidy_reviews %>%
  select(product, word, tf_idf) %>%
  pivot_wider(names_from = word, names_prefix = "word_",
              values_from = tf_idf, values_fill = 0)
impairment_spec <- 
  boost_tree(trees = tune(), min_n = tune(), tree_depth = tune(), learn_rate = tune(), 
    loss_reduction = tune(), sample_size = 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants