yihui / formatR

Format R Code Automatically
https://yihui.org/formatr/
257 stars 51 forks source link

A pre-commit hook for `formatR` #97

Open fabianegli opened 2 years ago

fabianegli commented 2 years ago

It would be great to have formatR available as a pre-commit hook to keep R projects formatted consistently.

Since version 2.11.0, pre-commit supports R.

I would be glad to help implementing one if that is desired.

yihui commented 2 years ago

I'm not familiar with pre-commit. Please feel free to submit a pull request if it's simple enough. Thanks!

lorenzwalthert commented 2 years ago

Just for your interest, I built the R integration of pre-commit and I maintain a bunch of hooks, including a hook to format code with {styler}, at https://github.com/lorenzwalthert/precommit. You can add support for pre-commit to this {formatR} repo, as described in the link above. If you need help, let me know.

fabianegli commented 2 years ago

@lorenzwalthert That looks nice - And I think for the repo I had in mind to use the pre-commit hook in I might actually end up recommending your style-files hook. And any help to implement the hook for formatR is of course welcome. I'm attempting that for the first time.

lorenzwalthert commented 2 years ago

I hope the above linked docs are self-explanatory, but I think you are the first one to attempt using it (apart from myself), so it's a good test to see if the docs are complete.