Skip to content

Error in loadNamespace(x) : there is no package called ‘precommit’ with {renv} #602

Closed
@rressler

Description

@rressler

I am on a silicon mac have installed the latest versions of pre-commit (using Homebrew) and precommit. 26 October 2024.

  • I had to add an environment variable in .RProfile for R to find pre-commit: options(precommit.executable = "/opt/homebrew/bin/pre-commit")

The first three hooks in the default .pre-commit-config.yaml all fail. with the error: Error in loadNamespace(x) : there is no package called ‘precommit’

I am able to get the hooks to work by adding an RScript to ensure the renv::load() occurs. I thought this was supposed to happen with activate.R.

I am able to fix the first hook by adding an entry value.

 -   id: style-files
        args: [--style_pkg=styler, --style_fun=tidyverse_style]
        entry: Rscript -e "renv::load(); styler::style_dir()"

I am able to fix the second hook, but one file at a time. I could use regex to get more but you get the idea.

 id: spell-check
        args: [--langs=en-US]
        entry: Rscript -e "renv::load();spelling::spell_check_files('./app/app.R')"
        entry: Rscript -e "renv::load();spelling::spell_check_files('./R/varsutils_functions.R')"

I am able to fix the lintr hook as well.

    -   id: lintr
        args: [--warn_only]
        entry: Rscript -e "renv::load(); lintr::lint_dir()"

I would like to be able to use the default pre-commit-config.yaml file without having to force renv to load for those hooks that use precommit in their code.

Originally, precommit was only installed in this repo. I then installed it for all users. It made no difference.

I checked the paths to packages as well.

> .libPaths()
[1] "/Users/rressler/Library/CloudStorage/OneDrive-american.edu/my_aws_repos/shiny_varsutils_aws/renv/library/macos/R-4.4/aarch64-apple-darwin20"
[2] "/Users/rressler/Library/Caches/org.R-project.R/R/renv/sandbox/macos/R-4.4/aarch64-apple-darwin20/f7156815"  

Am I missing something in linking precommit, pre-commit, and renv? Please let me know.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions