5

I'm setting up a git workflow with my R project using packrat. Everytime I packrat::snapshot() my workspace, the file packrat.lock changes with the new packages/versions etc, but it also changes the Hash line for each package, which is a bit annoying when checking file diffs to see what changed from one commit to another.

Is this Hash really necessary? If not, is there any way to disable it?

gsmafra
  • 2,434
  • 18
  • 26

1 Answers1

0

The hash is generated by the hidden hash() function in packrat library, and it serves as a package consistency check.

The algorithm generates an md5sum that is based on the DESCRIPTION file included in the package tarball, but there is additional logic involved, see lines #103-#107 in the packrat/R/cache.R source at Github.

In order to obtain the HASH that packrat expects to find in the packrat.lock file a direct call to the hash() function must be made. This function is not exposed in the compiled package, so the only way to access it is to use the packrat source.

  1. Obtain a copy of the source of the packrat library from CRAN with the correct version
  2. Extract it into a folder (in my example it is packrat-0.5.0)
  3. Start an R session

The following lines demonstrate how to generate the hash for the package BH-1.66.0-1 (4cc8883584b955ed01f38f68bc03af6d):

# md5sum() function is neeeded
library(tools)

# relevant source code files are loaded
source('packrat-0.5.0/R/utils.R') # readDcf() function
source('packrat-0.5.0/R/cache.R') # packrat's hash() function

# execute the hash() function on the DESCRIPTION file in the package
print(hash('/usr/local/lib/R/site-library/BH/DESCRIPTION'))

This should return the correct HASH of 4cc8883584b955ed01f38f68bc03af6d.

I am not aware of any options in packrat that would allow you to disable HASH checking. If your goal is to manually modify the packrat.lock file to alter a package version, it is certainly possible by performing this trick.

This could help overcome some minor dependency issues. However, there are two dangers:

  1. such a package version change may start a cascade of dependency upgrade requirements
  2. errors appear in your app because of compatibility issues
Viktor Horváth
  • 139
  • 2
  • 3