Learn R Programming

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

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

931

Version

0.4.2

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Lorenz Walthert

Last Published

April 10th, 2024

Functions in precommit (0.4.2)

hook_state_create

Create a hook state
install_impl

Install pre-commit on your system with conda
roxygen_assert_additional_dependencies

Assert if all dependencies are installed
may_require_permanent_cache

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

Roxygen and add a cache entry
run_test_impl

Implement a test run
not_conda

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

Run a test
path_precommit_exec

Locate the pre-commit executable
set_config_source

Set the location to a config file
path_derive_precommit_exec_path

Derive the pre-commit executable from the path
release_gh

Create a new release on GitHub
precommit-package

precommit: Pre-Commit Hooks
release_complete

Complete the release
path_derive_precommit_exec_win_python3plus_base

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

Install pre-commit on your system
snippet_generate

Generate code snippets
open_config

Open pre-commit related files
update_rev_in_config

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

Update the pre-commit executable
precommit_docopt

Provide a singular interface for hook calls to docopt
uninstall_precommit

Uninstall pre-commit
rev_read

Read the refs corresponding to a hooks repo
local_test_setup

Testing utilities
update_impl

Updates pre-commit on your system with conda
use_ci

Use continuous integration with pre-commit
use_precommit

Get started with pre-commit
precommit_executable_file

The name of the executable file
path_derive_precommit_exec

Derive the path to the pre-commit executable
use_precommit_config

Initiate a pre-commit config file
version_precommit

Retrieve the version of the pre-commit executable used
robust_purl

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

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

Auto-update your hooks
dirs_R.cache

Create the path to the precommit R.cache cache
call_and_capture

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

Fallback doc
hook_state_assert

Check if the hook produced what you want
generate_uninstalled_pkg_name

Generate a random package name that is not installed
get_os

Get the operating System
git_init

Initiate git and configure it
call_precommit

Call pre-commit
ensure_named

Name the input
communicate_captured_call

Communicate a captured call
diff_requires_run_roxygenize

Check if we should run roxygen.
empty_on_cran

Reduce a check to the empty string on CRAN
path_derive_precommit_exec_impl

Find an executable
path_derive_precommit_exec_conda

Derive the path to the conda pre-commit executable