Skip to contents

Running precommit in R

Overview

Pre-commit hooks are scripts that run automatically before a commit is finalized in Git. They’re used to catch issues early by enforcing checks like code formatting, linting, or running tests before changes are committed.

Rprecommit is a package that allows you to run pre-commit checks in R. This package is inspired by the package lorenzwalthert/precommit.Rprecommit is designed to run pre-commit WITHOUT ANY PYTHON DEPENDENCIES.

The package is still under development and new features will be added in the future.

Installation

The latest version can be installed from GitHub as follows:

install.packages("devtools")
devtools::install_github("alexym1/Rprecommit")

Usage

Initialize pre-commit framework

Rprecommit::install_precommit()

Run hooks

Rprecommit::run_precommit()

Add hooks

Editing the .pre-commit-config file using Rprecommit::edit_precommit_config():

repos:
  - repo: local
    hooks:
      - id: renv
        name: Synchronize project from renv.lock
        description: Synchronize the project from the renv.lock
        entry: Rscript inst/pre-commit/hooks/synchronize_project.R
        language: system
        pass_filenames: false

Code of conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.