Skip to content

Consistent code style #96

Closed
Closed

Description

@cbeleites

As @GegznaV very rightly says:

In my opinion, R Code style is a bit inconsistent in hyperSpec. I used styler package with the "Tidyverse" rules for automatic code style corrections followed by manual corrections spotted out by RStudio code style diagnostic tools. NOTE. If these corrections are unacceptable in hyperSpec, the authors of the package should write an R code writing style guidelines and use the style consistently throughout the vignettes, examples and R script files. It would be better if (1) linting (i.e., code style checking) rules are created for automatic checking (e.g., see package lintr and (2) if styler rules are created for doing automatic corrections (e.g., the authors of mlr package implemented their own rules).

Activity

  1. added this to the Version 1.0 milestone on Jan 14, 2020
  2. cbeleites commented on Jan 14, 2020

    @cbeleites
    OwnerAuthor

    I'm very much in favor of overhauling hyperSpec with styler().

    There is one point where I personally would like to differ from tidyverse style: I find a slightly more "spacy" style that has a space between function name and opening parenthesis easier to read, so:
    log (10) instead of log(10).

    However, I'd like to hear your opinions on this:

    • log (10) (space after function name easier to read):
    • log(10) (no space) easier to read:
    • improvement not worth deviating from tidyr:
  3. pinned this issue on Jan 14, 2020
  4. added
    Topic: documentation 📘
    on Jan 14, 2020
  5. bryanhanson commented on Jan 15, 2020

    @bryanhanson
    Collaborator

    I have generally been very happy with the default settings in styler, at least I don't care strongly enough about some items to figure out how to do them differently! However, if you (CB) want to keep your extra spacing, that's not too hard if it is already present:

    style_text("logx <- log(10)") # logx <- log(10)
    style_text("logx <- log (10)") # logx <- log(10)
    style_text("logx <- log(10)", strict = FALSE) # logx <- log (10) # CB style
    

    I found this at this blog. So I would propose styling with strict = FALSE and then perhaps a little clean up. I can do this by the end of the weekend if you like (I just returned from a trip and have a lot of things to address as a result!).

  6. GegznaV commented on Jan 15, 2020

    @GegznaV
    Collaborator

    I would prefer not to deviate from the tidyverse style as:

    1. I personally find additional spacing a bit annoying, e.g., log (10) or chondro [[]] look to me as two different "words". In my work, I usually use the Tidyverse style as much as possible and if there are some deviations from the style, it is a distraction, that does not allow working as efficiently as possible. But really it is a matter of habit.
    2. RStudio linting tools automatically suggest fixing this kind of syntax (see the blue underline and the blue (i) icon):
      image

    NOTE: By default, the styler fixes log (10) into log(10), but does not fix spacing before squared brackets, e.g., chondro [[]]

  7. cbeleites commented on Jan 15, 2020

    @cbeleites
    OwnerAuthor

    @bryanhanson: it's not too difficult to define and use a custom transformer that gives the extra space (I put one together before starting the discussion to make sure ;-)).

    @GegznaV: the same is true for linting with lintr (with custom configuration in a .lint file for the project)

    The additional effort would thus be small.

    However the poll found:

    • 2x preference for not having spaces
    • 1x slight preference for spaces
    • 1x no strong preference

    => let's stick to tidyverse defaults

    I'll style() the R/ directory in the next days and then close this issue. The vignettes are IMHO best style()d as part of the translation process to .Rmd.

  8. unpinned this issue on Jun 19, 2020
  9. added
    Topic: style ✏️
    on Jun 21, 2020
  10. cbeleites commented on Jun 22, 2020

    @cbeleites
    OwnerAuthor

    I think we can close this since it is by now in CONTRIBUTING.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Note: guidelineNote: help wantedTopic: documentation 📘Topic: style ✏️

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions