Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{renv} fails to record {precommit} in renv.lock and raises there is no package called 'precommit' error #1983

Open
philiporlando opened this issue Sep 16, 2024 · 3 comments

Comments

@philiporlando
Copy link

philiporlando commented Sep 16, 2024

I'm trying to use {precommit} with my project, but I'm experiencing the below error:

> git commit -m "update R script"
style-files.............................................................. Failed
- hook id: style-files
- exit code: 1

- One or more packages recorded in the lockfile are not installed.
- Use `renv::status()` for more details.
- One or more packages recorded in the lockfile are not installed.
- Use `renv::status()` for more details.
Error in packageVersion("precommit") : 
  there is no package called ‘precommit’
Execution halted

I have already installed ran the following within my project:

renv::install("precommit")
# The following package(s) will be installed:
#   - precommit [0.4.3]
# These packages will be installed into "~/Projects/test-pre-commit-styler/renv/library/R-4.1/x86_64-pc-linux-gnu".
# 
# Do you want to proceed? [Y/n]: y
# 
# # Installing packages -------------------------------
# - Installing precommit ...                      OK [linked from cache]
# Successfully installed 1 package in 26 milliseconds.

renv::status()
# No issues found -- the project is in a consistent state.

precommit::version_precommit()
# [1] "3.4.0"

packageVersion("precommit")
# [1] ‘0.4.3’

precommit::autoupdate()
# ✔ Ran `pre-commit autoupdate ()` to get the latest version of the hooks.

However, {precommit} isn't tracked anywhere within my renv.lock file:

{
  "R": {
    "Version": "4.1.3",
    "Repositories": [
      {
        "Name": "CRAN",
        "URL": "https://cloud.r-project.org"
      }
    ]
  },
  "Packages": {
    "renv": {
      "Package": "renv",
      "Version": "1.0.7",
      "Source": "Repository",
      "Repository": "RSPM",
      "Requirements": [
        "utils"
      ],
      "Hash": "397b7b2a265bc5a7a06852524dabae20"
    }
  }
}

Updating one of my R scripts to include a call to {precommit} is a workaround to force {renv} to record its usage in the renv.lock, but this feels like a hack, and it unfortunately yields the same error about precommit not being recorded in the lockfile...

I'm hoping to better understand how to get {renv} to recognize that I'm using {precommit} with my project, regardless if its namespace is references within any R scripts, and to resolve this loadNamespace(x) : there is no package called 'precommit' error... Any insight is appreciated!

Here is a reprex.

@philiporlando philiporlando changed the title {renv} fails to record {precommit} in renv.lock {renv} fails to record {precommit} in renv.lock and raises there is no package called 'precommit' error Sep 16, 2024
@SaranjeetKaur
Copy link

Hi there,

Did you find any solution? I am facing the same issue.

@philiporlando
Copy link
Author

I haven't found a solution to this yet.

@lorenzwalthert
Copy link

lorenzwalthert commented Oct 28, 2024

author of {precommit} here. I know docs could be better but {precommit} manages it's own renv that is stored outside of your git root. Your project {renv} it's lockfile etc has nothing to do with it. If you search the issues in the https://github.com/lorenzwalthert/precommit, you should find a few similar issues and a link to the wiki on how you should be able to resolve the issue: https://github.com/lorenzwalthert/precommit/wiki/Packages-are-not-found-after-R-upgrade. Also, if you are interested in how {precommit} uses {renv}, please see here: https://github.com/lorenzwalthert/precommit/wiki/What-happens-under-the-hood-when-I-install-the-hooks%3F

If you have further questions, I suggest to continue the discussion in lorenzwalthert/precommit#602.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants