All Projects → lorenzwalthert → Precommit

lorenzwalthert / Precommit

Licence: gpl-3.0
pre-commit hooks for R projects

Programming Languages

r
7636 projects

Projects that are alternatives of or similar to Precommit

Use Interval
A custom React Hook that provides a declarative setInterval called useInterval.
Stars: ✭ 127 (-9.93%)
Mutual labels:  hooks
React Use Scrollspy
Flexible React Hook to automatically update navigation based on scroll position
Stars: ✭ 133 (-5.67%)
Mutual labels:  hooks
Wpgulp
An advanced Gulp workflow for WordPress development with extensive documentation. Used by 40,000+ themes and plugins.
Stars: ✭ 1,733 (+1129.08%)
Mutual labels:  workflow
Tipdm
TipDM建模平台,开源的数据挖掘工具。
Stars: ✭ 130 (-7.8%)
Mutual labels:  workflow
Mern Authentication
MERN stack authentication boilerplate: password reset, email verification, server sessions, redux, hooks and docker for dev and prod.
Stars: ✭ 129 (-8.51%)
Mutual labels:  hooks
Pure Store
A tiny immutable store with type safety.
Stars: ✭ 133 (-5.67%)
Mutual labels:  hooks
Wana
Easy observable state for React ⚡️
Stars: ✭ 128 (-9.22%)
Mutual labels:  hooks
Qmui web
An efficient front-end framework for developers building UI on the web.
Stars: ✭ 1,719 (+1119.15%)
Mutual labels:  workflow
Tipple
A lightweight dependency-free library for fetching data over REST with React.
Stars: ✭ 133 (-5.67%)
Mutual labels:  hooks
Use Less
React hooks that help you do what you already did, with more indirection
Stars: ✭ 135 (-4.26%)
Mutual labels:  hooks
Window Size
React hook for subscribing to window size
Stars: ✭ 130 (-7.8%)
Mutual labels:  hooks
Microflow
Lightweight workflow engine
Stars: ✭ 129 (-8.51%)
Mutual labels:  workflow
Go Codon
Workflow based REST framework code generator
Stars: ✭ 133 (-5.67%)
Mutual labels:  workflow
Hookish
Hooks in to interesting functions and helps reverse the web app faster.
Stars: ✭ 129 (-8.51%)
Mutual labels:  hooks
Alfred
My Alfred Theme And Workflow
Stars: ✭ 135 (-4.26%)
Mutual labels:  workflow
Use Is In Viewport
A react hook to find out if an element is in a given viewport with a simple api.
Stars: ✭ 129 (-8.51%)
Mutual labels:  hooks
React Atom
A simple way manage state in React, inspired by Clojure(Script) and reagent.cljs
Stars: ✭ 133 (-5.67%)
Mutual labels:  hooks
React Circular Input
React components for easily composing a circular range input
Stars: ✭ 141 (+0%)
Mutual labels:  hooks
Workflowshare
Workflow实例分享
Stars: ✭ 137 (-2.84%)
Mutual labels:  workflow
Git Cola
git-cola: The highly caffeinated Git GUI
Stars: ✭ 1,787 (+1167.38%)
Mutual labels:  vcs

Useful git pre-commit hooks for R

CRAN status Lifecycle: experimental R build status

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 the code is parsable, making sure you have not forgotten a comma, brace or quote.

The goal of this package is to twofold:

  • Provide a set of hooks that are useful when your git repo contains R code.

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

The following online docs are available:

Installation

You can install the package from CRAN:

install.packages("precommit")

To access pre-commit functionality from R, you also need to install the pre-commit framework. The following command line methods are tested to work with this R package (and accessing them from outside R is easier and use is slightly faster):

  • $ pip3 install pre-commit --user (macOS, Linux and Windows) outside a conda or virtual environment.

  • $ brew install pre-commit (macOS).

Alternatively, you can handle the installation from R using miniconda:

  • install miniconda if you don’t have it already: reticulate::install_miniconda(). This needs reticulate >= 1.14.

  • install the pre-commit framework with precommit::install_precommit() into the conda environment r-precommit. Do not install other packages into this environment.

Then, in a fresh R session:

# once in every git repo either
# * after cloning a repo that already uses pre-commit or
# * if you want introduce pre-commit to this repo
precommit::use_precommit()

The last command initializes pre-commit in your repo and performs some set-up tasks like creating the config file .pre-commit-config.yaml, where the hooks that will be run on git commit are specified. See ?precommit::use_precommit() to see how you can use a custom .pre-commit-config.yaml instead of the default at initialization. You can (obviously) change edit the file manually at any time.

Usage

The next time you run git commit, the hooks listed in your .pre-commit-config.yaml will get executed before the commit. The helper function precommit::open_config() let’s you open and edit the .pre-commit-config.yaml conveniently from the RStudio console. When any file is changed due to running a hook or the hook script errors, the commit will fail. You can inspect the changes introduced by the hook and if satisfied, you can add the changes made by the hook to the index with git add path/to/file and attempt to commit again. Some hooks change files, like the styler hook, so all you need to do to make the hook pass is git add the changes introduced by the hook. Other hooks, like the parsable-R hook, will need your action, e.g. add a missing closing brace to a call like library(styler, before they pass at the next attempt. If all hooks pass, the commit is made. You can also temporarily disable hooks. If you succeed, it should look like this:

See the hooks provided by this repo under vignette("available-hooks"). You can also add other hooks from other repos, by extending the .pre-commit-config.yaml file, e.g. like this:

-   repo: https://github.com/pre-commit/precommit
    rev: v1.2.3
    hooks: 
    -   id: check-added-large-files

To update the hook revisions, run precommit::autoupdate().

Caution

  • Do not abort while hooks are running in RStudio git tab. Non-staged changes are stashed to a temp directory and when you abort in RStudio, these changes are not brought back to you repo. Upvote this issue to change this. We hope that in the future, the changes will be recovered in RStudio too. Note that this is only an issue with RStudio. Stashes are restored when you abort a git commit with INT (e.g. Ctrl+C) on the command line. To restore stashes, manually after hitting abort in the RStudio git tab, you can git apply /path/to/patch_with_id whereas you find the patch under your pre-commit cache, which is usually under $HOME/.cache/pre-commit/.

  • Because R is not officially supported as a language in the pre-commit framework (yet), there is no R package dependency management for the R hooks provided in this repo. If an R package that is needed by a hook is not yet installed, you might get this error:

# > Error in loadNamespace(name) : there is no package called ‘__name_of_package__’

In that case, just install the package with install.packages() once and try to commit again. All R dependencies of the pre-commit hooks provided in this repo are suggested dependencies of this R package, so if you want to install them all, just install.packages("precommit", dependencies = c("Imports", "Suggests")).

Documentation

The online documentation of this package only covers the functionality added on top of pre-commit by this package. Everything else is covered in the extensive online documentation of the pre-commit framework itself, including how to:

  • create pre-push hooks

  • create local hooks

  • and more

Update

To update the pre-commit executable, use the update utilities provided by your installation method. If you chose conda, you can use precommit::update_precommit().

You can check the version of you executable with precommit::version_precommit().

Uninstallation

uninstall_precommit("repo") # just for the repo you are in.
uninstall_precommit("user") # remove the pre-commit conda executable.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].