renv snapshot to detect local source installation

Dear all,

I would like to address this situation.
I am using renv to capture the packages. At the same time, the only CRAN available repo is the one allowed by my company which is limited. To install package outside of the CRAN's company, I am providing the package as tarball and installing from source.

Then use the following code to provide source location in the lock file

library(renv)
# Custom Package description
package_name <- "<PACKAGE_NAME>"
package_version <- "<PACKAGE_VERSION>"
package_source <- paste0("renv/local/", package_name, "_", package_version, ".tar.gz")

# Modifying lock file based on package description
lockfile <- renv:::renv_lockfile_read("renv.lock")
lockfile$Packages[[package_name]]$Package <- package_name
lockfile$Packages[[package_name]]$Version <- package_version
lockfile$Packages[[package_name]]$Source <- package_source
renv:::renv_lockfile_write(lockfile, "renv.lock")

However, the workflow in my company is using a git hook doing a snapshot, thus erasing the local source info in the lock file.

My question is:
Is there a way for renv to snapshot automatically packages installed from source?

Many thanks!

I'm not sure what renv can do to help in this particular case, then.

Perhaps instead the solution is to override some of the lockfile fields during restore? You could do something like:

record <- list(Package = <package>, Version = <version>, Source = <source>)
options(renv.records = list(<package> = record))
renv::restore()

And this would instruct renv to "ignore" the lockfile entry and use the version defined in renv.records instead.