Debian Codegraph @

R/refresh.R

raw
1
2 #' Refresh the local cache of available packages
3 #'
4 #' Query the active R package repositories for available packages, and
5 #' update the in-memory cache of those packages.
6 #'
7 #' Note that \R also maintains its own on-disk cache of available packages,
8 #' which is used by `available.packages()`. Calling `refresh()` will force
9 #' an update of both types of caches. renv prefers using an in-memory
10 #' cache as on occasion the temporary directory can be slow to access (e.g.
11 #' when it is a mounted network filesystem).
12 #'
13 #' @return A list of package databases, invisibly -- one for each repository
14 #' currently active in the \R session. Note that this function is normally
15 #' called for its side effects.
16 #'
17 #' @export
18 #'
19 #' @examples
20 #' \dontrun{
21 #'
22 #' # check available packages
23 #' db <- available.packages()
24 #'
25 #' # wait some time (suppose packages are uploaded / changed in this time)
26 #' Sys.sleep(5)
27 #'
28 #' # refresh the local available packages database
29 #' # (the old locally cached db will be removed)
30 #' db <- renv::refresh()
31 #'
32 #' }
33 refresh <- function() {
34
35 pkgtype <- getOption("pkgType", default = "source")
36
37 srcok <- pkgtype %in% c("both", "source") ||
38 getOption("install.packages.check.source", default = "yes") %in% "yes"
39
40 binok <- pkgtype %in% "both" ||
41 grepl("binary", pkgtype, fixed = TRUE)
42
43 list(
44 binary = if (binok) available_packages(type = "binary", limit = 0L),
45 source = if (srcok) available_packages(type = "source", limit = 0L)
46 )
47
48 }