Skip to content

Commit

Permalink
Use CRAN PACKAGES file as fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
walkowif committed Jan 8, 2024
1 parent cfafd9e commit 8491030
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ Simply list the types of dependencies which should not cause the `renv.lock` gen
locksmith --allowIncompleteRenvLock 'Imports,Depends,Suggests,LinkingTo'
```

## Updating existing `renv.lock`

TODO

## Development

This project is built with the [Go programming language](https://go.dev/).
Expand Down
19 changes: 17 additions & 2 deletions cmd/renv.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,12 @@ func UpdateRepositoryPackages(renvLock *RenvLock, updatePackageRegexp string,
}
log.Trace("Package ", k, " matches updated packages regexp ",
updatePackageRegexp)
var repositoryPackagesFile PackagesFile
repositoryPackagesFile, ok := packagesFiles[v.Repository]
if !ok {
log.Error("Could not retrieve PACKAGES file for ", v.Repository, " repository.")
continue
log.Error("Could not retrieve PACKAGES file for ", v.Repository, " repository.\n",
"Attempting to use CRAN's PACKAGES file as a fallback.")
repositoryPackagesFile = packagesFiles["CRAN"]
}
var newPackageVersion string
for _, singlePackage := range repositoryPackagesFile.Packages {
Expand Down Expand Up @@ -264,6 +266,19 @@ func GetPackagesFiles(renvLock RenvLock) map[string]PackagesFile {
packagesFile := ProcessPackagesFile(packagesFileContent)
repositoryPackagesFiles[repositoryName] = packagesFile
}

// Check if the PACKAGES file from a repository named CRAN has been downloaded.
_, ok := repositoryPackagesFiles["CRAN"]
if !ok {
// If not, save CRAN's PACKAGES file to be used as a fallback, for packages which
// (according to renv.lock) should be downloaded from a repository not defined in
// the renv.lock header.
_, _, cranPackagesContent := DownloadTextFile(
"https://cloud.r-project.org/src/contrib/PACKAGES", make(map[string]string),
)
cranPackagesFile := ProcessPackagesFile(cranPackagesContent)
repositoryPackagesFiles["CRAN"] = cranPackagesFile
}
return repositoryPackagesFiles
}

Expand Down

0 comments on commit 8491030

Please sign in to comment.