Learn R Programming

⚠️There's a newer version (0.4.3) of this package.Take me there.

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.3.2

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Lorenz Walthert

Last Published

July 1st, 2022

Functions in precommit (0.3.2)

fallback_doc

Fallback doc
autoupdate

Auto-update your hooks
open_config

Open pre-commit related files
install_precommit

Install pre-commit on your system
call_precommit

Call pre-commit
may_require_permanent_cache

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

Create a hook state
diff_requires_run_roxygenize

Check if we should run roxygen.
ensure_named

Name the input
dirs_R.cache

Create the path to the precommit R.cache cache
git_init

Initiate git and configure it
hook_state_assert

Check if the hook produced what you want
extract_diff_root

Extract old and new lines from git diff --cached
generate_uninstalled_pkg_name

Generate a random package name that is not installed
local_test_setup

Testing utilities
install_impl

Install pre-commit on your system with conda
path_derive_precommit_exec

Derive the path to the pre-commit executable
call_and_capture

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

Create a new release on GitHub
copy_artifacts

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

Derive the pre-commit executable from the path
not_conda

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

Derive the path to the conda pre-commit executable
path_derive_precommit_exec_win_python3plus_base

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

Find an executable
precommit_executable_file

The name of the executable file
snippet_generate

Generate code snippets
uninstall_precommit

Uninstall pre-commit
robust_purl

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

Read the refs corresponding to a hooks repo
roxygen_assert_additional_dependencies

Assert if all dependencies are installed
release_complete

Complete the release
path_precommit_exec

Locate the pre-commit executable
update_precommit

Update the pre-commit executable
precommit-package

precommit: Pre-Commit Hooks
use_precommit

Get started with pre-commit
use_precommit_config

Initiate a pre-commit config file
use_ci

Use continuous integration with pre-commit
roxygenize_with_cache

Roxygen depending on cache state
update_impl

Updates pre-commit on your system with conda
update_rev_in_config

Updates the hook version ref of precommit in a .pre-commit-config file
run_test_impl

Implement a test run
set_config_source

Set the location to a config file
version_precommit

Retrieve the version of the pre-commit executable used
run_test

Run a test