You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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
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
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.
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 =.
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.
Activity
lorenzwalthert commentedon Jan 26, 2018
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 thisCreated on 2018-01-26 by the reprex package (v0.1.1.9000).
Note that, as stated in the examples section of
tidyverse_style, the argumentindent_bywas first passed fromstyle_text()totransformers = style(...)via.... You could have specified it directly in the transformers argumentBut 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 oftidyverse_style()and give it a new namefrom 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_quotesin 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 filesR/rules-*.Rwhere * 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.lorenzwalthert commentedon Jan 26, 2018
As far as the other rules go: here my quick take on them:
=in function calls (token EQ_SUB, trystyler:::get_parse_data("call(a = 2); function(x = 22){}")to find out which token has which text): usestyle_space_around_token()to set indention to zero for this token and adapt the rulestyle_space_around_math_tokenso it does not contain=.lorenzwalthert commentedon Feb 7, 2018
How is it going @llrs? Is this still an open issue?
llrs commentedon Feb 7, 2018
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