Skip to content

Style for Bioconductor #331

Closed
Closed

Description

@llrs

Nice package, thanks for developing it.

I develop a package in Bioconductor which is following its coding style. It has its own checking (style) package ,BiocCheck, to check conformation with Bioconductor style. However it doesn't modify the code.

I would like to create a style for Bioconductor, but I don't understand how to make it (yet). I have seen that there is extensive documentation of how it works (which I haven't read nor understood it fully). But I haven't seen how to modify/create a new style. Mainly I would like to modify the indentation from 2 spaces to 4 from the tidyverse_style just to begin with. How should I do this?

I tried looking at tidyverse_style()[["indentation"] but I didn't understand the code, or how to modify/replace to change the output.
Many thanks

Activity

  1. lorenzwalthert commented on Jan 26, 2018

    @lorenzwalthert
    Collaborator

    Hi @llrs, great to hear this. I am happy to support you in this project. I admit that styler might look a bit daunting at first, but to create a new style guide is not all that complicated. I suggest you to first (after you read this reply I mean) read the vignette on how you can customise styler, fork the project and run the code yourself to get a feeling for it. The vignette contains an example on how to implement a style guide with one rule: Always put { on a new line.
    In particular, I think it's crucial to understand the structure of the nested parse table, i.e. that at the top level, you have some tokens, and in the column child, there are all tokens that are contained in this expression.

    tidyverse_style()["indention"] (not indentation) contains a list with transformer functions (in this case transformer that modify indention) that are applied on every level of nesting of the parse table. In the case of the tidyverse style guide, that is just one function that changes indention for function declarations. The general level of indention is not set there.

    So to answer your first question: There is an indention option in tidyverse_style(), so if you just want to style with 4 spaces indention, do this

    library("styler")
    style_text("a <- function(){ \na \n}", style = tidyverse_style, indent_by = 4)
    #> a <- function() {
    #>     a
    #> }

    Created on 2018-01-26 by the reprex package (v0.1.1.9000).

    Note that, as stated in the examples section of tidyverse_style, the argument indent_by was first passed from style_text() to transformers = style(...) via .... You could have specified it directly in the transformers argument

    style_text("a <- function(){ \na \n}", transformers = tidyverse_style(indent_by = 4))

    But we thought it's a nice feature of R to use ... to make things a bit simple (if you use the default style guide.

    However, eventually, you probably need to create your own style guide, for example if you want to add more rules to your style guide of remove some from tidyverse_style(). Then, I suggest to just copy / paste the definition of tidyverse_style() and give it a new name

    bioconductor_style <- function(scope = "tokens",
     ...

    from the source code of styler and modify it according to your wishes. If you don't want certain rules from the tidyverse style guide to be in your style guide, you need to remove the corresponding transformer functions from the style guide. I.e. if you don't want single quotes to be replaced with double quotes, you need to delete the line fix_quotes in your style guide (which is, as all other elements that are enumerated there, a transformer function). You can find all rules we defined in the files R/rules-*.R where * is spacing, line_break, other and replacement for the corresponding rules respectively. Also, setting a break point in a transformer function and inspect the environment as you style might help you to understand how things work.

  2. lorenzwalthert commented on Jan 26, 2018

    @lorenzwalthert
    Collaborator

    As far as the other rules go: here my quick take on them:

    • Enforcing line width currently not possible with styler (Enforcing a 80-character line length rule? #247).
    • no space around = in function calls (token EQ_SUB, try styler:::get_parse_data("call(a = 2); function(x = 22){}") to find out which token has which text): use style_space_around_token() to set indention to zero for this token and adapt the rule style_space_around_math_token so it does not contain =.
    • etc.
  3. lorenzwalthert commented on Feb 7, 2018

    @lorenzwalthert
    Collaborator

    How is it going @llrs? Is this still an open issue?

  4. llrs commented on Feb 7, 2018

    @llrs
    Author

    Definitely I would like to have the style, but I got to work on one of my packages. I hope to invest some time in this either this weekend or the next one.

    But thanks for the reminder

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions