r-lib / usethis
1
#' Use "latest" versions of all dependencies
2
#'
3
#' Pins minimum versions of dependencies to latest ones (as determined by `source`).
4
#' Useful for the tidyverse package, but should otherwise be used with extreme care.
5
#'
6
#' @keywords internal
7
#' @export
8
#' @param overwrite By default (`FALSE`), only dependencies without version
9
#'   specifications will be modified. Set to `TRUE` to modify all dependencies.
10
#' @param source Use "local" or "CRAN" package versions.
11
use_latest_dependencies <- function(overwrite = FALSE, source = c("local", "CRAN")) {
12 1
  deps <- desc::desc_get_deps(proj_get())
13 1
  deps <- update_versions(deps, overwrite = overwrite, source = source)
14 1
  desc::desc_set_deps(deps, file = proj_get())
15

16 1
  invisible(TRUE)
17
}
18

19
update_versions <- function(deps, overwrite = FALSE, source = c("local", "CRAN")) {
20 1
  baserec <- base_and_recommended()
21 1
  to_change <- !deps$package %in% c("R", baserec)
22 1
  if (!overwrite) {
23 1
    to_change <- to_change & deps$version == "*"
24
  }
25

26 1
  packages <- deps$package[to_change]
27 1
  versions <- switch(match.arg(source),
28 1
    local = map_chr(packages, ~ as.character(utils::packageVersion(.x))),
29 1
    CRAN = utils::available.packages()[packages, "Version"]
30
  )
31 1
  deps$version[to_change] <- paste0(">= ", versions)
32

33 1
  deps
34
}

Read our documentation on viewing source code .

Loading