I have created a virtual environment with rvenv, so that I now have rvenv/
in my project root. I have also installed styler
, and would like to have a pre-commit hook that will apply it to R code.
From here: https://github.com/lorenzwalthert/precommit/blob/master/.pre-commit-hooks.yaml is the following:
- id: style-files
name: style-files
description: style files with styler
args: [--style_pkg=styler, '--style_transformers=tidyverse_style(scope = "tokens")']
entry: inst/bin/style-files
language: script
files: '(\.R|\.Rmd|\.Rnw|\.r|\.rmd|\.rnw)$'
I'm confused about the path that should be given to entry:
, in this snip it's a path to a global version of styler
(or at least, I'm assuming so). But I would like to be able to use the version that I have installed in the virtual environment I assume.
My question is - how to go about doing this. If I shouldn't be using the version installed in renv/
then I'm happy to hear (and use) whatever the best practice is around creating a pre-commit hook to style R files that will work on mine and others systems.
Following the answer below worked, I had to install docopt as well (as outlined here).
Usually you rely on the remote repository to provide the configuration (such that you don't need all of the args
/ entry
/ etc. setup
for example if you want to use style-files
from the repository you've listed you'd set this in your .pre-commit-config.yaml
:
repos:
- repo: https://github.com/lorenzwalthert/precommit
rev: v0.1.2
hooks:
- id: style-files
from there you can customize args
/ etc.