r-multiverse / help

Discussions, issues, and feedback for R-multiverse
https://r-multiverse.org
MIT License
2 stars 2 forks source link

available.packages user-guidance #45

Closed dgkf closed 2 months ago

dgkf commented 3 months ago

I only discovered this after being baffled by package installs at one point, but the order of repositories listed in options("repos") does not indicate precedence as suggested here.

Given the packages in all "repos", available.packages will return the latest version of each package by default (regardless of which repo it comes from). The order of "repos" only factors in if there are version ties.

From ?available.packages, emphasis mine:

By default, the return value includes only packages whose version and OS requirements are met by the running version of R, and only gives information on the latest versions of packages.

and

built-in filters: "duplicates" Only report the latest version where more than one version is available, and only report the first-named repository (in ‘contriburl’) with the latest version if that is in more than one repository.

You can alter this behavior using options("available_packages_filters")

options(available_packages_filters = list(
  # these are the defaults, except for "duplicates" which de-duplicates by omitting all but the most recent
  "R_version", "OS_type", "subarch",
  # custom function to filter `available.packages()` matrix
  "precedence by repo order" = function(ap) { .. } 
))
llrs commented 3 months ago

Might be worth to link to the thread in r-package-devel with some (background) information/comments about this.

wlandau commented 3 months ago

Thanks, just submitted a PR for this: https://github.com/r-multiverse/r-multiverse.github.io/pull/14. This is all great to know, and in the R-multiverse docs, I would prefer to avoid making specific claims about the nuances of install.packages() or available.packages().