Skip to content

Commit

Permalink
Merge branch 'master' into system-requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
jimhester authored Aug 3, 2020
2 parents 3eed997 + b662690 commit 61bcb27
Show file tree
Hide file tree
Showing 37 changed files with 978 additions and 157 deletions.
13 changes: 7 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,29 @@ License: GPL-3
Encoding: UTF-8
LazyData: true
ByteCompile: true
RoxygenNote: 6.1.1
RoxygenNote: 7.0.2
Roxygen: { library(roxygenlabs); list(markdown = TRUE) }
Depends:
R (>= 3.2)
Imports:
callr (>= 3.0.0.9002),
cli (>= 1.0.1),
cliapp (>= 0.0.0.9002),
crayon (>= 1.3.4),
desc (>= 1.2.0),
filelock (>= 1.0.2),
glue (>= 1.3.0),
pkgcache (>= 1.0.3),
pkgdepends (>= 0.0.0.9006),
pkgload,
pkgsearch (>= 3.0.2.9000),
prettyunits,
processx,
ps (>= 1.3.0),
rprojroot (>= 1.3.2),
utils
Remotes:
r-lib/pkgdepends
Roxygen: list(markdown = TRUE)
Depends:
R (>= 3.2)
r-lib/pkgdepends,
r-hub/pkgsearch
Suggests:
covr,
mockery,
Expand Down
14 changes: 14 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
# Generated by roxygen2: do not edit by hand

S3method("[",pak_search_result)
S3method(print,pak_search_result)
S3method(print,pkg_install_result)
export(cache_clean)
export(cache_delete)
export(cache_list)
export(cache_summary)
export(lib_status)
export(local_install)
export(local_install_deps)
export(local_install_dev_deps)
export(local_system_requirements)
export(meta_clean)
export(meta_list)
export(meta_summary)
export(meta_update)
export(pak_cleanup)
export(pak_setup)
export(pak_sitrep)
export(pkg_deps)
export(pkg_download)
export(pkg_install)
export(pkg_list)
export(pkg_remove)
export(pkg_search)
export(pkg_status)
importFrom(utils,head)
244 changes: 244 additions & 0 deletions R/cache.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@

#' Package cache utilities
#'
#' @description
#' Various utilities to inspect and clean the package cache.
#' See the pkgcache package if you need for control over the package cache.
#'
#' @details`cache_summary()` returns a summary of the package cache.
#'
#' @return `cache_summary()` returns a list with elements:
#' * `cachepath`: absolute path to the package cache
#' * `files`: number of files (packages) in the cache
#' * `size`: total size of package cache in bytes
#'
#' @export
#' @rdname cache
#' @examplesIf FALSE
#' # Summary
#' cache_summary()

cache_summary <- function() {
remote(
function(...) {
get("cache_summary_internal", asNamespace("pak"))(...)
},
list()
)
}

cache_summary_internal <- function() {
pkgcache::pkg_cache_summary()
}

#' @details `cache_list()` lists all (by default), or a subset of
#' packages in the package cache.
#'
#' @param ... For `cache_list()` and `cache_delete()`, `...` may contain
#' filters, where the argument name is the column name. E.g. `package`,
#' `version`, etc. Call `cache_list()` without arguments to see the
#' available column names. If you call `cache_delete()` without arguments,
#' it will delete all cached files.
#'
#' @return `cache_list()` returns a tibble with the data about the cache.
#'
#' @rdname cache
#' @export
#' @examplesIf FALSE
#' # List packages
#' cache_list()
#' cache_list(package = "recipes")
#' cache_list(platform = "source")

cache_list <- function(...) {
remote(
function(...) {
get("cache_list_internal", asNamespace("pak"))(...)
},
list(...)
)
}

cache_list_internal <- function(...) {
pkgcache::pkg_cache_find(...)
}

#' @details `cache_delete()` deletes files from the cache.
#'
#' @return `cache_delete()` returns nothing.
#' @export
#' @rdname cache
#' @examplesIf FALSE
#' # Delete packages
#' cache_delete(package = "knitr")
#' cache_delete(platform = "macos")

cache_delete <- function(...) {
remote(
function(...) {
get("cache_delete_internal", asNamespace("pak"))(...)
},
list(...)
)
invisible()
}

cache_delete_internal <- function(...) {
pkgcache::pkg_cache_delete_files(...)
}

#' @details `cache_clean()` deletes all files from the cache.
#'
#' @return `cache_clean()` returns nothing.
#'
#' @export
#' @rdname cache
#' @examplesIf FALSE
#' cache_clean()

cache_clean <- function() {
remote(
function(...) {
get("cache_clean_internal", asNamespace("pak"))(...)
},
list()
)
invisible()
}

cache_clean_internal <- function() {
pkgcache::pkg_cache_delete_files()
}

#' Metadata cache utilities
#'
#' @description
#' Various utilities to inspect, update and clean the metadata cache.
#' See the pkgcache package if you need for control over the metadata cache.
#'
#' @details `meta_summary()` returns a summary of the metadata cache.
#'
#' @return `meta_summary()` returns a list with entries:
#' * `cachepath`: absolute path of the metadata cache.
#' * `current_db`: the file that contains the current metadata database.
#' It is currently an RDS file, but this might change in the future.
#' * `raw_files`: the files that are the downloaded `PACKAGES*` files.
#' * `db_files`: all metadata database files.
#' * `size`: total size of the metadata cache.
#'
#' @export
#' @rdname metadata
#' @examplesIf FALSE
#' # Metadata cache summary
#' meta_cummary()

meta_summary <- function() {
remote(
function(...) {
get("meta_summary_internal", asNamespace("pak"))(...)
},
list()
)
}

meta_summary_internal <- function() {
ret <- pkgcache::meta_cache_summary()
list(
cachepath = ret$cachepath,
current_db = ret$current_rds,
raw_files = ret$raw_files,
db_files = ret$rds_files,
size = ret$size
)
}

#' @details `meta_list()` lists all (or some) packages in the metadata
#' database.
#'
#' @param pkg Package names, if specified then only entries for `pkg`
#' are returned.
#' @return `meta_list()` returns a data frame (tibble) of all available
#' packages in the configured repositories.
#'
#' @export
#' @rdname metadata
#' @examplesIf FALSE
#' # The current metadata DB
#' meta_list()
#' # Selected packages only
#' meta_list(pkg = c("shiny", "htmlwidgets"))

meta_list <- function(pkg = NULL) {
remote(
function(...) {
get("meta_list_internal", asNamespace("pak"))(...)
},
list(pkg = pkg)
)
}

meta_list_internal <- function(pkg) {
pkgcache::meta_cache_list(packages = pkg)
}

#' @details `meta_update()` updates the metadata database. You don't
#' normally need to call this function manually, because all pak functions
#' (e.g. [pkg_install()], [pkg_download()], etc.) call it automatically,
#' to make sure that they use the latest available metadata.
#'
#' @return `meta_update()` returns nothing.
#'
#' @export
#' @rdname metadata
#' @examplesIf FALSE
#' # Update the metadata DB
#' meta_update()

meta_update <- function() {
remote(
function(...) {
get("meta_update_internal", asNamespace("pak"))(...)
},
list()
)
invisible()
}

meta_update_internal <- function() {
pkgcache::meta_cache_update()
}

#' @details `meta_clean()` deletes the whole metadata DB.
#'
#' @param force If `FALSE`, then pak will ask for confirmation.
#' @return `meta_clean()` returns nothing
#'
#' @export
#' @rdname metadata
#' @examplesIf FALSE
#' # Delete the metadata DB
#' meta_clean()

meta_clean <- function(force = FALSE) {
if (!force) {
force <- get_confirmation2(
"? Do you want to delete all package metadata (Y/n) "
)
}
if (!force) {
msg("x Metadata cleanup aborted")
return(invisible())
}

remote(
function(...) {
get("meta_clean_internal", asNamespace("pak"))(...)
},
list()
)
invisible()
}

meta_clean_internal <- function() {
pkgcache::meta_cache_cleanup(force = TRUE)
}
27 changes: 12 additions & 15 deletions R/confirmation.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

print_package_list <- function(x, new_version = NULL, old_version = NULL) {
cliapp::cli_div(
cli::cli_div(
class = "pkglist",
theme = list(div.pkglist = list("margin-left" = 2)))

Expand All @@ -11,8 +11,7 @@ print_package_list <- function(x, new_version = NULL, old_version = NULL) {
x <- paste0(x, " (", new_version, ")")
}

cliapp::cli_text(paste(x, collapse = ", "))
cliapp::cli_text()
cli::cli_text("{x}")
}

should_ask_confirmation <- function(sol) {
Expand All @@ -35,13 +34,12 @@ print_install_details <- function(sol, lib) {
# Should we ask?
should_ask <- should_ask_confirmation(sol)

cliapp::cli_text(" ")
if (n_newly) {
cliapp::cli_alert("Will {emph install} {n_newly} packages:")
cli::cli_alert("Will {.emph install} {n_newly} packages:")
print_package_list(sol$ref[newly], sol$version[newly])
}
if (n_upd) {
cliapp::cli_alert("Will {emph update} {n_upd} packages:")
cli::cli_alert("Will {.emph update} {n_upd} packages:")
print_package_list(sol$ref[upd], sol$version[upd], sol$old_version[upd])
}

Expand All @@ -58,30 +56,29 @@ print_install_details <- function(sol, lib) {
any_unk <- length(u_dl) > 0

if (n_dl == 0) {
cliapp::cli_alert("All {n_ch} packages ({b_ch}) are cached.")
cli::cli_alert("All {n_ch} packages ({b_ch}) are cached.")

} else if (n_ch == 0) {
if (n_dl - u_dl > 0) {
cliapp::cli_alert("Will {emph download} {n_dl - u_dl} CRAN packages ({b_dl}).")
cli::cli_alert("Will {.emph download} {n_dl - u_dl} CRAN packages ({b_dl}).")
}
if (u_dl > 0) {
cliapp::cli_alert("Will {emph download} {u_dl} packages with unknown size.")
cli::cli_alert("Will {.emph download} {u_dl} packages with unknown size.")
}

} else if (!any_unk) {
cliapp::cli_alert(
"Will {emph download} {n_dl} packages ({b_dl}), cached: {n_ch} ({b_ch}).")
cli::cli_alert(
"Will {.emph download} {n_dl} packages ({b_dl}), cached: {n_ch} ({b_ch}).")

} else {
if (n_dl - u_dl > 0) {
cliapp::cli_alert(
"Will {emph download} {n_dl - u_dl} CRAN packages ({b_dl}), cached: {n_ch} ({b_ch}).")
cli::cli_alert(
"Will {.emph download} {n_dl - u_dl} CRAN packages ({b_dl}), cached: {n_ch} ({b_ch}).")
}
if (u_dl > 0) {
cliapp::cli_alert("Will {emph download} {u_dl} packages with unknown size.")
cli::cli_alert("Will {.emph download} {u_dl} packages with unknown size.")
}
}
cliapp::cli_text(" ")

invisible(should_ask)
}
Expand Down
1 change: 0 additions & 1 deletion R/onload.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pkg_data <- new.env(parent = emptyenv())
crayon.colors = as.numeric(Sys.getenv("R_PKG_PKG_NUM_COLORS", "1"))
)
use_private_lib()
cliapp::start_app(theme = cliapp::simple_theme())

} else {
## In a subprocess of a worker
Expand Down
Loading

0 comments on commit 61bcb27

Please sign in to comment.