precommit initial CRAN release

[This article was first published on Posts on Lorenz Walthert, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I am happy to announce that {precommit} 0.1.2 is available from CRAN. Pre-commit hooks are tests that run each time you attempt to commit. If the tests pass, the commit will be made, otherwise not. A very basic test is to check if code is syntactically valid, making sure you have not forgotten a comma, brace or quote. Such hooks increase the quality of commits and the consistency in a code base. The goal of this package is to twofold:

  • Provide a set of hooks that are useful when your git repo contains R code. Examples are styling files with {styler} or to make sure there is no browser() in your code. Check out the list of currently supported hooks from this package.

  • Provide usethis-like functionality for common tasks such as installation and set-up and config file modification.

Note that because pre-commit is a language agnostic framework to manage git hooks, you can add other useful hooks to your git repo that are written in / for other languages, e.g. hooks from https://github.com/pre-commit/pre-commit-hooks. Some useful other hooks I discovered in this repo are:

  • check-added-large-files makes sure you don’t commit huge files accidentally.

  • end-of-file-fixer make sure all your committed files have a blank line at the end.

  • formatters for yaml, python and other file types.

There is also a list with many more repos that contain useful hooks.

Convinced? Let’s get started. You’ll find all relevant installation and usage instructions in the README.

If you already use {precommit}…

To guarantee a smooth experience, I suggest everyone who currently uses a devel version to upgrade both the R package (with install.package("precommit")) and the hook reversion (with precommit::autoupdate()). Depending on which devel version you use, we might also have added new hooks and changed the order in the default config file for a better user experience, so you could also make a copy of your current .pre-commit-config.yaml file and then use precommit::use_precommit(force = TRUE) in your repo to replace the config file and then manually port your deviations from the template config to the new config.

If you use conda, you may need to precommit::install_precommit(force = TRUE). You can also check the changelog for breaking changes we introduced before the CRAN release so you can adapt. In particular:

  • conda and reticulate are no longer required.

  • a few arguments in the API were renamed.

  • the speed of some hooks was improved through caching.

If you are a GitHub Action specialist..

We currently use travis in a non-standard setup because we also have to test different installation methods (pip, conda, brew) on different platforms (macOS, Linux, Windows), but I’d like to switch to GitHub Actions. If you have experience and want to contribute to this, please open an issue on GitHub.

To leave a comment for the author, please follow the link and comment on their blog: Posts on Lorenz Walthert.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)