Learn R Programming


editor_options: markdown: wrap: 72

Useful git pre-commit hooks for R

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. You can run hooks locally and/or in the cloud:

  • As a check before local commits: This requires installing pre-commit.

  • As a CI check with https://pre-commit.ci: If you want to enforce passing hooks on pull requests (and auto-fix trivial problems like styling) even if the committer does not have a local installation.

Goals of the package

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.

Why do I need pre-commit hooks?

For a more in-depth explanation and even more reasons, see vignette("why-use-hooks").

Documentation

The following online docs are available:

These only cover the functionality added on top of the pre-commit framework by this package. Everything else is covered in the extensive online documentation of the pre-commit framework itself, including how to create hooks for actions like git push or git checkout, create local hooks etc.

Copy Link

Version

Install

install.packages('precommit')

Monthly Downloads

829

Version

0.4.3

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Lorenz Walthert

Last Published

July 22nd, 2024

Functions in precommit (0.4.3)

path_derive_precommit_exec_path

Derive the pre-commit executable from the path
path_derive_precommit_exec

Derive the path to the pre-commit executable
use_ci

Use continuous integration with pre-commit
update_impl

Updates pre-commit on your system with conda
use_precommit

Get started with pre-commit
uninstall_precommit

Uninstall pre-commit
precommit_docopt

Provide a singular interface for hook calls to docopt
run_test

Run a test
release_gh

Create a new release on GitHub
precommit_executable_file

The name of the executable file
release_complete

Complete the release
path_derive_precommit_exec_impl

Find an executable
roxygenize_with_cache

Roxygen and add a cache entry
roxygen_assert_additional_dependencies

Assert if all dependencies are installed
path_derive_precommit_exec_conda

Derive the path to the conda pre-commit executable
set_config_source

Set the location to a config file
hook_state_assert

Check if the hook produced what you want
get_os

Get the operating System
path_derive_precommit_exec_win_python3plus_base

Where are executables on Windows for Python 3 and higher?
use_precommit_config

Initiate a pre-commit config file
snippet_generate

Generate code snippets
version_precommit

Retrieve the version of the pre-commit executable used
path_precommit_exec

Locate the pre-commit executable
precommit-package

precommit: Pre-Commit Hooks
run_test_impl

Implement a test run
update_precommit

Update the pre-commit executable
rev_read

Read the refs corresponding to a hooks repo
robust_purl

Run knitr::purl(), setting the chunk option purl to TRUE if it's not already set to a literal value.
update_rev_in_config

Updates the hook version ref of {precommit} in a .pre-commit-config file
call_precommit

Call pre-commit
autoupdate

Auto-update your hooks
install_precommit

Install pre-commit on your system
not_conda

The testing environment does not use a conda environment if the env variable PRECOMMIT_INSTALLATION_METHOD is not 'conda'.
dirs_R.cache

Create the path to the precommit R.cache cache
copy_artifacts

Copy some file to the test directory that must be present, but are not passed to the hook as a file argument.
diff_requires_run_roxygenize

Check if we should run roxygen.
git_init

Initiate git and configure it
may_require_permanent_cache

Issue a warning if {R.cache} uses temporary cache only
communicate_captured_call

Communicate a captured call
call_and_capture

Make a call with system2() and capture the effects.
empty_on_cran

Reduce a check to the empty string on CRAN
fallback_doc

Fallback doc
ensure_named

Name the input
local_test_setup

Testing utilities
generate_uninstalled_pkg_name

Generate a random package name that is not installed
hook_state_create

Create a hook state
install_impl

Install pre-commit on your system with conda
open_config

Open pre-commit related files