-
Notifications
You must be signed in to change notification settings - Fork 71
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
Other style guides #340
Comments
I think there is no postponed issue with concrete plans on other style guides. However, I created a style guide that removes all comments in #334 (comment), and that was quick. So I think it's not a lot of work. For me, the question is also how we want to handle style guides other than the tidyverse style guide in general:
I think these questions are important to make explicit decisions on as the number of third-party style guides may grow over time and a consistent strategy should be adopted. What's your @krlmlr take on that? |
For these two I'd be fine if they lived in styler but were not exported for now. It feels like we need to play with a "proof of concept" first before thinking about organization. I'd let the handling of additional style guides be part of the upcoming GSoC project. |
In styler and not exported sounds good to me. |
Reference: The package oneliner implements a third-party style guide as a package and might help shaping a refined understanding of how we could organise and distribute new style guides. |
I am currently working on implementing a style guide for the mlr package within styler: mlr-org/mlr#2278 |
On the topic of supporting custom style guides, you might also want to consider the possibility of |
Thanks @riccardoporreca. I'll fork your fork (haha) and try it out when I get the chance. I first want to submit styler 1.02. to CRAN |
Sure, go ahead with the |
Working on the mlr style guide. Reference: mlr-org/mlr#2278 |
Related: a blog post for modifying the tidyverse style guide if you are not a styler expert. https://lorenzwalthert.netlify.com/posts/customizing-styler-the-quick-way/ |
I tried to use "Set style" from the add-in menu in RStudio, and set it to styler::tidyverse_style(scope = 'line_breaks') This break styling, throwing the following errors: > styler:::style_active_file()
Using style `styler::tidyverse_style(scope='line_breaks')`
Error in get_addins_style_fun()() : attempt to apply non-function
> styler:::style_selection()
Using style `styler::tidyverse_style(scope='line_breaks')`
Error in style(...) : could not find function "style" Am I doing something wrong, or can I not customize the styling in this way? |
Not currently, but we are just working on that for a week or so (#500). Please install that branch from GitHub and tell me if it works: remotes::install_github("r-lib/styler#500") |
Removed old package using > library(styler)
> styler:::style_selection()
Using style transformers`styler::tidyverse_style(scope = 'line_breaks')`
Error in style(...) : could not find function "style" > sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.4
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] styler_1.1.0.9000
loaded via a namespace (and not attached):
[1] compiler_3.6.0 backports_1.1.4 magrittr_1.5 tools_3.6.0 pillar_1.3.1 rstudioapi_0.10 tibble_2.1.1 crayon_1.3.4 pkgconfig_2.0.2 rlang_0.3.4 purrr_0.3.2 |
I am not sure I can reproduce this. Can you re-start R and RStudio? |
Trying to use ale with I know that you can set the style for the addin in
I do not know how I should specify an external style function via this setting. Some of our devs are working in VIM and it would be great to use the new styler ale implementation! (if this belongs into a separate issue, feel free to move it. Did not want to hijack that other discussion.) |
@lorenzwalthert
Styling active document: > styler:::style_active_file()
Using style transformers`styler::tidyverse_style()` works Style selection: > styler:::style_selection()
Using style transformers`styler::tidyverse_style()`
Error in style(...) : could not find function "style" does not work Then I tried used "Set style" to change the style in use and set it to: styler::tidyverse_style(scope = 'line_breaks') Results:
|
@lorenzofanchi sorry I missed that you were styling the selection only. Thanks for the hint. It should be fixed now in the aforementioned branch. |
@lorenzwalthert awesome, I'll try the updated version now! Another question: is the set style remembered across RStudio restarts? |
No, it is not. You need to put something like this in your .Rprofile (e.g. via options(styler.addins_style_transformer = "styler::tidyverse_style(scope = 'line_breaks')") So when R starts, it sets this option. |
Great stuff, thanks a lot for all the help and effort developing this incredibly useful tool! |
@pat-s: I don't use VIM, so I am not sure. Here is the PR in the ale repo: https://github.com/w0rp/ale/pull/2401/files. From looking at the diff, I can at least tell that you'd need a function name there from some namespace. But you could use the mlr-style branch fork the fork you got from me and then specify that as the option, i.e. If it is not working, maybe @tvatter could jump in. Also @tvatter, I think as we saw with #500, it is better to supply the transformers, not the style, because that would allow for much richer style specification. Should we do a breaking API change PR to fix this problem before the next release?
I don't think so. Any style guide, you just need to be able to find it at runtime. So you could also use oneliner I think. I just think it must be in a package namespace because otherwise there is no way to find it for the |
Yeah, sorry, I didn't know much about |
I did that and it did not work. But I accidentally had CRAN styler installed for some reason. It works with the fork just as expected 👍 @tvatter |
@pat-s ok great it worked. But the customization is not just for other style guides, also for customization within the tidyverse style guide. I.e. if one does want to style with scope tidyverse_style(scope = "linebreaks") To achieve that. I think this is more common. |
What is the current policy dealing with custom style guides? Updating my fork constantly with all `styler' commits is tedious. I see that there is also #451 and possibly others? I see the problem related to dealing with custom style guides (ensuring quality, responding to updates/PR). Maybe the easiest would be to have styler being the API with custom packages that serve specific style guides. |
It's good that I was mentioned in this issue, I get the reminder from time to time that I needed to address this style vs transformers in VIM. This is done now. Sorry for the delay given that there was only two lines of code to change. |
Have no clue about your style. Major diffs of the "mlr-style" are to use 2 spaces for indentation and |
Thanks for the clarification @pat-s. I'm not too fussed about 2 spaces (as opposed to tab?) indentation and, as you would expect, 'equals style' ( |
Here is the repo for the mlr-style. |
Hello! I am a programmer working in an existing R codebase that is not consistent and I'm looking for some easy wins to get it to a consistent styling. This appears to be a wonderful package, but it is very unclear how to support custom stylings that can be shared across the team environment. I have just integrated a However I see no equivalent for how to do so in Do you have guidance on how to support custom configurations AND configure it such that other teams working in this repository will default to those settings? |
First, in case you have not seen these, I point to a few existing resources related to your question of creating a new style guide:
If you read this thread carefully, it becomes evident that there is no final solution to this problem. Maybe not yet. The cleanest would probably be to create a In any case, we don't really recommend creating your own style guide unless you have very good reasons for it. Since the tidyverse style guide is very popular and in our perspective elegant, we recommend to use it in almost all projects. Also note that it is non-invasive and you have a few options to customise it in many ways. Check Sharing of custom style guides is also a bit difficult.
|
I think it's documented now in #846. |
Heads-up anyone following this and @yihui, and @pat-s in particular I've created a minimal {styler.equals} package building on a nice template by @lorenzwalthert: https://github.com/Robinlovelace/styler.equals There's also this: https://github.com/ropensci-review-tools/spaceout Not sure if these can go on CRAN due to use of |
most natural seems to be requesting export of key helper functions :) |
Was wondering if that would be a possibility and have opened an issue: #974. Thanks for the suggestion Michael! |
See r-lib/styler#340 (comment) for context
What would it take to support the following styles?
=
for assignment, use'
for strings)
and{
I'm sure there's a related postponed issue, but I haven't looked.
Edit: This is now documented in a few vignettes and we have a GitHub template for custom style guides.
The text was updated successfully, but these errors were encountered: