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

How to keep = as the assignment symbol? #860

Closed
ShixiangWang opened this issue Oct 29, 2021 · 13 comments
Closed

How to keep = as the assignment symbol? #860

ShixiangWang opened this issue Oct 29, 2021 · 13 comments

Comments

@ShixiangWang
Copy link

ShixiangWang commented Oct 29, 2021

Dear developers,

Thanks for developing this awesome tool. Sometimes I want to use a style that keep using = instead of <- of assignment symbol. Is there any easy way to do this? I check the functions but no options can be used for this setting like formatR.

BTW, the package languageserver provide a way to do this in VScode with:

options(languageserver.formatting_style = function(options) {
  style <- styler::tidyverse_style(indent_by = options$tabSize)
  style$token$force_assignment_op <- NULL # Not force modifying '=' to '<-'
  style
})

I don't know how to apply this for styler as no object can be assigned back.

Best,

Shixiang

@lorenzwalthert
Copy link
Collaborator

The tidyverse style guide does not support = for assignment, so you need to provide your own style guide to do this. Also, it's best to be consistent and not mix the two. The easiest way is to remove the rule as shown above. There is a vignette explaining it in more detail: https://styler.r-lib.org/dev/articles/remove_rules.html. To use this style with the addin, you need to create an R package that exports this style guide, and then set the R option styler.addins_style_transformer as described here.

@ShixiangWang
Copy link
Author

@lorenzwalthert Thanks for your response and suggestion. I am looking for a solution from the tool itself or a workaround from setting in .Rprofile.

@lorenzwalthert
Copy link
Collaborator

lorenzwalthert commented Oct 29, 2021

There is no solution from the tool itself, i.e. an out-of-the-box way of doing it., and we don't aim at providing one. If you were serious about it, you have to write your own style guide as an R package, i.e. the same way as the reference implementations. Then, you have the full flexibility with vs code, RStudio addin and {precommit}. Maybe someone else already did it, but I don't know of any.

@ShixiangWang
Copy link
Author

Thanks.

@lorenzwalthert
Copy link
Collaborator

if you develop such a package (it's not much code, as you see in the reference implementation), we can link it in the vignette. There is also https://github.com/ropensci-review-tools/spaceout.

@ShixiangWang
Copy link
Author

@lorenzwalthert Thanks for providing a good reference. I will take a try.

@lorenzwalthert
Copy link
Collaborator

lorenzwalthert commented Oct 29, 2021

Actually the best reference is probably https://github.com/lorenzwalthert/semicoloner. You can also c/p all of it and adapt where necessary.

@lorenzwalthert
Copy link
Collaborator

Let me try to create a GitHub template repo for it.

@ShixiangWang
Copy link
Author

@lorenzwalthert :) Thanks again.

@ShixiangWang
Copy link
Author

@lorenzwalthert If you use the solution for this as a template, I think I can get rid of coding for this. Hah 😄

@lorenzwalthert
Copy link
Collaborator

Here is the template repo with the rule you wanted: https://github.com/lorenzwalthert/styler.yours

@lorenzwalthert
Copy link
Collaborator

Related: #340.

@Robinlovelace
Copy link

Heads-up @lorenzwalthert and @ShixiangWang I have created a minimal {styler.equals} package building on Lorenz's great template: https://github.com/Robinlovelace/styler.equals

Want to join forces on this @ShixiangWang? It's not yet CRAN ready as it has this message on checks, is this something that's worth fixing upstream, in the template @lorenzwalthert ?

 All declared Imports should be used.
  Unexported objects imported by ':::' calls:
    ‘styler:::is_function_call’ ‘styler:::previous_non_comment’
    ‘styler:::scope_normalize’
    See the note in ?`:::` about the use of this operator.

0 errors ✔ | 0 warnings ✔ | 2 notes ✖

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

No branches or pull requests

3 participants