Available Hooks

Below is a comprehensive list with all hooks from {precommit} as well as their arguments or flags, if they take any. Other repos also host hooks, many are listed here.

Good to know

File modification

Some hooks will fail without changing the files you want to commit, like the lintr hook - and you need to make manual changes for the hook to pass on the next attempt. Other hooks like the styler hook write to files, and if that changes the file, the hook will fail, but this means you won’t need to modify the file manually, just stage the changes and try to commit again. Below, we indicate for every hook if it modifies files or not.


Arguments are specified as described in the pre-commit.com documentation, e.g. we can set the argument style_pkg to styler and style_fun to tidyverse_style for the hook style-files like this:

-   repo: https://github.com/lorenzwalthert/precommit
    rev: v0.1.3
    -   id: style-files
        args: [--style_pkg=styler, --style_fun=tidyverse_style]

Other hook settings

Apart from specifying the args key as described above, there are other hooks settings you can specify. If you don’t, they are inherited from the default repository’s configuration (i.e. the .pre-commit-hooks.yaml file in https://github.com/lorenzwalthert/precommit). See the pre-commit documentation, for the available settings.



A hook to style files with styler. Only commit code corresponding to the tidyverse style guide. Set argument style_pkg and style_fun if you want to use another style guide than the tidyverse style guide.

  id: style-files
  args: [--style_pkg=<styler>, --style_fun=<tidyverse_style>]

This hook modifies files.


Make sure README.Rmd hasn’t been edited more recently than README.md, i.e. remind you to render the .Rmd to .md before committing.

This hook does not modify files.


Checks if your .R files are “valid” R code by checking if running parse() on it returns an error.

This hook does not modify files.


Guarantees you that you don’t accidentally commit code with a browser() statement in it.

This hook does not modify files.


Checks spelling with spelling::spell_check_files().

Excluded files

When you invoke precommit::use_precommit() and .pre-commit-config.yaml is written to your repo (unless you specify config_source otherwise), we copy the expression in the exclude: key from spell check hook the default repository’s configuration (i.e. the .pre-commit-hooks.yaml file in https://github.com/lorenzwalthert/precommit) into your config file, so you can easily add or remove some files. As of v0.1.3, the following regex is used to exclude files following the verbose python regex syntax:



The lang arg will be passed to spelling::spell_check_files().

id: spell-check
args: [--lang=<language>]
exclude: <regular expresion>

This hook does not modify input files. It will add all words not found in the dictionary to inst/WORDLIST, assuming they were spelled correctly but were not in the dictionary. An example might be “RStudio”. The hook error message will contain all words written to inst/WORDLIST, so if there were really some typos, make sure to fix them and remove them from inst/WORDLIST. If there were not typos, or you fixed all, stage inst/WORDLIST and this time, the commit should pass.


A hook to run roxygen2::roxygenize(). Makes sure you commit your .Rd changes with the source changes. To take advantage of caching, you don’t need to run roxygen2::roxygenize() manually anymore.

This hook does not modify input files, but writes to .Rd files in man/.


Checks if packages used with the pkgname::fun() syntax are listed in your DESCRIPTION file. Flag allow_private_imports lets the user specify that private imports into the package namespace are tolerable, e.g. somepkg:::x(). Flag not set by default, i.e. the hook will fail if such a call is found.

id: deps-in-desc args: [--allow_private_imports] 

This hook does not modify the file DESCRIPTION because the user should decide for each package if it should go to Imports: or Suggests:, which can be done easily with usethis::use_package(). For those who use usethis::use_package(): As long as the CRAN version of the dependency {desc} is v1.2.0, we recommend you to install the GitHub version because otherwise, the new dependencies won’t be added in alphabetical order and after adding a dependency, use-tidy-description will fail in most cases (#85)[https://github.com/r-lib/desc/pull/85].


A hook to run usethis::use_tidy_description() to ensure dependencies are ordered alphabetically and fields are in standard order.

This hook does modify the file DESCRIPTION.


A hook to run lintr::lint() to check that R files are lint free. Argument warning_only changes the behavior of the pre-commit to be non-blocking. You should set this with the field verbose: true.

id: lintr
args: [--warn_only]
verbose: true

When configured this way, lintr prints lint errors as they appear. Other arguments are not supported. Instead, lintr config should be specified in a .lintr config file in Debian Control Field Format as specified in the .lintr documentation.

This hook does not modify any file.


Make sure DESCRIPTION hasn’t been edited more recently than codemeta.json, i.e. remind you to run codemetar::write_codemeta() in order to keep codemeta.json in sync with DESCRIPTION.

This hook does not modify any file.