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

Recommend styler over formatR suggestion #57

Closed
lcolladotor opened this issue Apr 17, 2020 · 11 comments · Fixed by #88
Closed

Recommend styler over formatR suggestion #57

lcolladotor opened this issue Apr 17, 2020 · 11 comments · Fixed by #88
Assignees
Labels
Beginner Beginner level Hackathon project

Comments

@lcolladotor
Copy link
Contributor

lcolladotor commented Apr 17, 2020

Hi,

Based on my recent work for r-lib/actions#84 and at https://github.com/leekgroup/derfinderPlot/blob/master/dev/02_update.R, I want to make a small PR to BiocCheck and http://www.bioconductor.org/developers/how-to/coding-style/. This is directly related to r-lib/styler#636.

While formatR has been really helpful, in my experience when I use it, I need to double check very carefully all the code as it might change the meaning of some of it. My understanding is that styler is the package that is best maintained now for styling code (you still need to check your code! but styler seems to do a better job) and I quickly stumbled upon it yesterday on a Google search. Unlike formatR, it's compatible with tidyverse code (magrittr pipes and multi-line piped code), it also updates the example code in roxygen2-formatted examples. For my derfinderPlot package (a small one I was testing things with), it didn't break any code unlike formatR (see r-lib/styler#636 for the quotes issue).

styler has a styler::tidyverse_style() function and at r-lib/styler#636 I'm suggesting creating a styler::bioc_style() or styler::bioc_like_style() function that builds upon their styler::tidyverse_function(). Even without such a function, you can currently use styler like I did so at https://github.com/leekgroup/derfinderPlot/blob/master/dev/02_update.R#L2-L12 when updating my derfinderPlot package. Hopefully they like the idea, at which point, I would make a PR in styler. Probably styler::bioc_like_style() is the better name since I wouldn't want the function to enforce things like camelCase, somefunc(a=1, b=2) over somefunc(a = 1, b = 2), but well, those aren't really checked by BiocCheck anyway.

Both styler and formatR have issues with line lengths as noted in r-lib/styler#247, but from what I read there, it's a very complicated problem.

For BiocCheck, if you like the idea, I'm suggesting making a PR that either recommends styler first and formatR second, or only recommends styler (given that styler seems to me more actively maintained). I would also like to make the same suggestion for http://www.bioconductor.org/developers/how-to/coding-style/ though I don't know if there's a GitHub repo for the Bioc website.

Best,
Leo

@lcolladotor
Copy link
Contributor Author

Ahh, I see that https://github.com/Bioconductor/bioconductor.org exists!

@lshep
Copy link
Contributor

lshep commented Apr 21, 2020

Would gladly accept pull requests!

@lshep
Copy link
Contributor

lshep commented Apr 21, 2020

Bioconductor/Contributions#1451 (comment) Proof -- this package very much liked it

@lcolladotor
Copy link
Contributor Author

Awesome! Thanks for letting me know Lori =)

I've been working on the getting GitHub Actions up and running for bioc packages at r-lib/actions#84 and this is my current status of check-bioc.yml from leekgroup/derfinderPlot@d586ae4. I'm in the process of applying this to several packages. Next I need to address Bioconductor/Contributions#1389 (comment) :P

Once I'm done with that, I'll get back to this ^_^

@mtmorgan
Copy link
Collaborator

my own feeling is that one gets 90% of the way there by implementing any commonly accepted style, without having to re-invent the wheel or quibble about details. Of course my own 'priority' is 4 versus two space indentation, and I'd be happy with a recommendation (on bioconductor.rog / BiocCheck; does it require a bioc_like_style()?

style_pkg(".", transformers=tidyverse_style(indent = 4))

@nturaga nturaga added this to To do in BiocCheck Hackathon May 6, 2020
@nturaga nturaga added Beginner Beginner level Hackathon project Hackathon labels May 6, 2020
lcolladotor added a commit to lcolladotor/biocthis that referenced this issue May 9, 2020
Created both an introductory and a developer's notes vignette, updated README
and docs with examples, added a second biocViews term, fixed some small
bugs/typos.

Related links (as many as I could remember):

* https://rstd.io/tidytools19
* https://twitter.com/CVWickham
* https://twitter.com/hadleywickham
* https://www.rstudio.com/products/rstudio/download
* https://comunidadbioinfo.github.io/post/building-tidy-tools-cdsb-runconf-2019/#.XrbLMxNKiu4
* http://bioconductor.org/
* https://lcolladotor.github.io/pkgs/
* https://stat.ethz.ch/pipermail/bioc-devel/2020-March/016365.html
* https://www.bioconductor.org/help/docker/
* https://stat.ethz.ch/pipermail/bioc-devel/2020-April/016532.html
* https://github.com/features/actions
* https://stat.ethz.ch/pipermail/bioc-devel/2020-April/016650.html
* r-lib/actions#84
* r-lib/usethis#1108
* r-lib/styler#636
* Bioconductor/BiocCheck#57
* Bioconductor/bioconductor.org#54
* http://bioconductor.org/developers/how-to/coding-style/
* https://style.tidyverse.org/
* https://twitter.com/lorenzwalthert
* https://twitter.com/mt_morgan
* https://docs.travis-ci.com/user/languages/r/
* r-lib/pkgdown#1206
* r-lib/pkgdown#1230
* https://twitter.com/jimhester_
* https://www.jimhester.com/talk/2020-rsc-github-actions/
* https://github.com/Bioconductor/BBS
* https://github.com/Bioconductor/packagebuilder
* https://www.appveyor.com/
* r-hub/rhub#52
* r-hub/rhub#38
* https://www.tidyverse.org/blog/2020/04/usethis-1-6-0/
* https://github.com/r-lib/actions/tree/master/examples
* https://yihui.org/en/2018/03/second-pull-request/
* https://github.com/r-lib/actions/blob/master/examples/check-standard.yaml
* https://help.github.com/en/actions
* https://ropenscilabs.github.io/actions_sandbox/
* https://twitter.com/seandavis12
* https://github.com/seandavi/BiocActions/blob/master/.github/workflows/main.yml
* https://twitter.com/CSoneson
* https://github.com/csoneson/dreval/blob/master/.github/workflows/R-CMD-check.yaml
* https://bioc-community.herokuapp.com/
* https://github.com/leekgroup/derfinderPlot/blob/master/.github/workflows/check-bioc.yml
* https://github.com/LieberInstitute/recount3/blob/master/.github/workflows/check-bioc.yml
* https://github.com/hpages
* r-lib/actions#68
* r-lib/actions#85
* https://twitter.com/opencpu
* https://community.rstudio.com/u/const-ae
* https://community.rstudio.com/t/compiler-support-fo-c-14-features-on-windows/57284/4
* r-lib/xml2#296
* r-lib/xml2#302
* https://github.com/r-lib/usethis/blob/master/.github/workflows/R-CMD-check.yaml
* https://github.com/r-lib/usethis/commits/master/.github/workflows/R-CMD-check.yaml
* https://stat.ethz.ch/pipermail/bioc-devel/2020-April/016703.html
* https://stat.ethz.ch/pipermail/bioc-devel/2020-April/thread.html
* r-lib/remotes#296
* r-lib/actions#86
* r-lib/covr#427
* https://github.com/r-lib/actions/blob/master/examples/pr-commands.yaml
* https://www.digitalocean.com/community/tutorials/how-to-install-git-on-ubuntu-18-04
* r-lib/actions#50
* actions/checkout#238
* https://github.com/rocker-org/rocker-versioned2/blob/master/dockerfiles/Dockerfile_rstudio_4.0.0-ubuntu18.04
* https://twitter.com/niteshturaga
* https://twitter.com/cboettig
* rocker-org/rocker-versioned#208
* https://github.community/t5/GitHub-Actions/bd-p/actions
* https://www.r-consortium.org/blog/2020/03/18/cdsb-diversity-and-outreach-hotspot-in-mexico
* https://github.com/maxheld83
* r-lib/actions#87
* https://github.com/yutannihilation
@lcolladotor
Copy link
Contributor Author

Hi,

As I described at r-lib/styler#636 (comment), I made a new R package called biocthis that implements the bioc_style() function. You can then use it like I have at https://github.com/lcolladotor/biocthis/blob/fe66af4a12334559fc7d7968e53de0e676cb8689/dev/04_update.R#L9-L22. That is:

## Automatically re-style the code in your package to a Bioconductor-friendly
## format
## Note that you can pair this function with the RStudio "Reformat code"
## button on the magic wand drop down menu. The keyboard shortcut is
## macOS: shift + command + A
## Windows: shift + control + A
styler::style_pkg(transformers = biocthis::bioc_style())
styler::style_dir(here::here("dev"), transformers = biocthis::bioc_style())
styler::style_dir(
    here::here("vignettes"),
    transformers = biocthis::bioc_style(),
    filetype = "Rmd"
)
styler::style_file(here::here("README.Rmd"), transformers = biocthis::bioc_style())

biocthis::bioc_style() is fairly simple and very similar to styler::tidyverse_style(indent = 4).

For the PR, would it be ok to mention both? If so, I'll send the PR soon here and then the one for Bioconductor/bioconductor.org#54 (comment).

Best,
Leo

@mtmorgan
Copy link
Collaborator

mtmorgan commented May 10, 2020

I like the idea of biocthis, but think that it is outside the scope of this hackathon.

Also I think it is not suitable as a pull request for BiocCheck, because it adds functionality (correcting problems) beyond the purpose of the package. In the process it introduces significant additional dependencies for relatively specialized function.

FWIW this pull request might find a better home in something like biocthis, which could have dependencies on packages (like projroot, ...), etc, that are not relevant to the main purpose of the package (BiocStyle).

How about developing biocthis as a separate collaborative project, maybe seeded with discussion on the slack developer forum? I could imagine the dependency analysis and build / check badge generation functions finding a home there, too.

@lcolladotor
Copy link
Contributor Author

lcolladotor commented May 11, 2020

Hi,

Clarifications

I think that we might have had some misunderstandings.

The PR I'm proposing for BiocCheck doesn't involve actual code, just the message that has the recommendations on the tools to use for addressing formatting issues. I wanted to ask whether it was ok to edit this message to mention https://lcolladotor.github.io/biocthis/articles/biocthis.html#bioc-style- or if it should only mention styler. That is:

styler::style_pkg(transformers = biocthis::bioc_style()) vs styler::style_pkg(transformers = styler::tidyverse_style(indent = 4)).

So this and Bioconductor/bioconductor.org#54 are really about documentation changes.

It might be best if I just send the PR to get this process started. I initiated this issue before the upcoming hackathon was announced, but I could wait until then if you prefer that option.

biocthis

It's become my "fun" (lots of debugging) side project since April that I've been working on the weekends. This past one I wrote the documentation for it (https://lcolladotor.github.io/biocthis/) and I'm planning on writing a blog post about it. Prompted by what you just said, I'll share the blog post on the Bioc Slack too. As it stands, it could also submit biocthis for formal peer review at Bioc (it now passes BiocCheck too).

BiocStyle/pull/76

I haven't looked in detail at the code in Bioconductor/BiocStyle#76, but yes, this could live in biocthis. It would complement (two functions to keep it simpler) the one I implemented at https://lcolladotor.github.io/biocthis/reference/use_bioc_vignette.html.

Best,
Leo

@mtmorgan
Copy link
Collaborator

Absolutely then updating BiocCheck to advocate for a specific tool for reformatting is in scope.

I think there is value in continuing to think of this (this issue) as part of the hackathon. At the least I think it would be valuable to provide other community members to hear / discuss this if desired...

@lcolladotor
Copy link
Contributor Author

Ok! I'll wait for the remote hackathon next week then =) I like the idea of getting community feedback.

@lcolladotor
Copy link
Contributor Author

In response to the 2020-05-18 BiocCheck-a-thon intro session: Count me in for resolving this issue (can you assign me to it? I can't self-assign). If anyone else is interested, please let me know. Thanks!

@lshep lshep closed this as completed in 5604071 May 29, 2020
lshep added a commit that referenced this issue May 29, 2020
   - version bump for Leonardo's PR
LiNk-NY pushed a commit that referenced this issue Aug 24, 2023
This commit resolves #57
by updating the `handleMessage()` calls after the formatting check
fails. Instead of mentioning `formatR`, these messages now refer to:

* `styler`,
* `biocthis`,
* the `BiocCheck` vignette.

Furthermore, the `BiocCheck` vignette section on formatting still
mentions `formatR`, but it now also mentions in more detail:

* `styler`: how to install and run it
* `biocthis`: as a companion to `styler` with code how to run it
(but not install it since it's optional and the install instructions
will hopefully change soon once this package is submitted/reviewed).
* a quick overview of the differences between `formatR` and `styler`,
though this is mostly done by highlighting current limitations of
`formatR`.
* how RStudio Desktop's `Reformat code` button (under the magic wand)
can help break long lines which is something that `styler` cannot do
as discussed in more detail at
r-lib/styler#247. `formatR` can do this,
but personally, the fact that it broke valid R code in some of my
packages made me trust its output less.

The NEWS and DESCRIPTION files have been updated accordingly.


Former-commit-id: 5604071
LiNk-NY pushed a commit that referenced this issue Aug 24, 2023
   - version bump for Leonardo's PR


Former-commit-id: e4993b2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Beginner Beginner level Hackathon project
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

4 participants