# Anatomy of a Lockfile

`renv` uses a lockfile to capture the state of your library at some point in time. It is stored as a collection of records, with different records defining:

- The version of `renv` used when generating the lockfile;
- The version of `R` used in that project;
- The R repositories that were active when the lockfile was created;
- Package records defining each R package, their version, and their installation source.

Here is an example lockfile, including the packages `markdown` and `mime`:

    {
      "R": {
        "Version": "4.2.0",
        "Repositories": [
          {
            "Name": "CRAN",
            "URL": "https://cloud.r-project.org"
          }
        ]
      },
      "Packages": {
        "markdown": {
          "Package": "markdown",
          "Version": "1.0",
          "Source": "Repository",
          "Repository": "CRAN",
          "Hash": "4584a57f565dd7987d59dda3a02cfb41"
        },
        "mime": {
          "Package": "mime",
          "Version": "0.7",
          "Source": "Repository",
          "Repository": "CRAN",
          "Hash": "908d95ccbfd1dd274073ef07a7c93934"
        }
      }
    }

The function `renv::snapshot()` is used to create this lockfile, and by default writes these records to the file `renv.lock`. Later, if you need to reinstall the specific package versions as recorded in `renv.lock`, you can use `renv::restore()`.