-
-
Notifications
You must be signed in to change notification settings - Fork 51
Description
I am trying to use the roxygenize hook on an R package that is not located in the repo root. As per the documentation in available hooks, I have used the --root argument to specify the relative path to the package source. However, this alone causes the roxygenize hook to skip saying there are no files to check.
If I add files: to point to the package folder with pass_filenames: false, the roxygenize hook runs but fails with error "Error: Unknown arguments: '--root'".
To Reproduce
The following batch script may be used to reproduce the bug in Windows (tested using the latest version of R, precommit and the hook):
set PACKAGE_NAME=mypackage
set REPO_PATH=repo
mkdir %REPO_PATH%
cd %REPO_PATH%
:: Create new R package structure using package.skeleton
Rscript -e "f <- \(x) x" -e "package.skeleton(name='%PACKAGE_NAME%', list='f')"
:: Initialize git repository in current directory first
git init
:: Create .pre-commit-config.yaml file
echo Creating pre-commit configuration...
(
echo repos:
echo - repo: https://github.com/lorenzwalthert/precommit
echo rev: v0.4.3.9013
echo hooks:
echo - id: roxygenize
echo args: [--root=%PACKAGE_NAME%]
echo files: %PACKAGE_NAME%
echo pass_filenames: false
) > .pre-commit-config.yaml
:: Add all files to git
git add .
git commit -m "Initial commit: R package setup with pre-commit"
:: Install pre-commit hooks
pre-commit install
:: Run pre-commit on all files
pre-commit run --all-files
This gives the following output:
roxygenize...............................................................Failed
- hook id: roxygenize
- exit code: 1
- The project is out-of-sync -- use `renv::status()` for details.
- The project is out-of-sync -- use `renv::status()` for details.
Run roxygen2::roxygenize()
Obviously, this hook is only activated when any staged file passes the filter
specified in .pre-commit-hooks.yaml. Then, we check the time stamp of the last
time we ran the hook. If any of our R files is younger than that, we consider
running the hook. We next use {git2r} to inspect the cached diff of all .R files
in the R/ directory, and not the files passed to this hook. If we find any
roxygen2 comment in the diff, we run `roxygen2::roxygenize(). The preliminary
use case for this is when we previously attempted to commit but check failed, so
on the second try without any other files changed, it will succeed.
This check should run *after* check that modify the files that are passed to
them (like styler) because they will never modify their input .R files.
Usage:
roxygenize [--no-warn-cache] [--root=<root_>] <files>...
Options:
--no-warn-cache Suppress the warning about a missing permanent cache.
--root=<root_> Path relative to the git root that contains the R package root [default: .].
Error: Unknown arguments: '--root'
Execution halted
Expected behavior
I would expect the hook to run on the R package without complaining about an unknown argument --root.
Additional context
- My operating system is: Windows 11 24H2
- R version: 4.5.1
- Rtools version: 4.5