Skip to content

Commit

Permalink
Revert "Add src argument to check_installed()"
Browse files Browse the repository at this point in the history
This reverts commit 3101076.
  • Loading branch information
lionel- committed Dec 16, 2021
1 parent 4d75056 commit 8d9b6a9
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 65 deletions.
43 changes: 6 additions & 37 deletions R/session.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,13 @@ as_version_info <- function(pkg, call = caller_env()) {
}

#' @rdname is_installed
#' @param src A [pak
#' source](https://pak.r-lib.org/reference/pak_package_sources.html)
#' specification passed to `pak::pkg_install()` when `pkg` needs to
#' be installed or reinstalled.
#' @inheritParams args_error_context
#' @export
check_installed <- function(pkg,
reason = NULL,
...,
version = NULL,
compare = NULL,
src = NULL,
call = caller_env()) {
check_dots_empty0(...)

Expand All @@ -188,22 +183,14 @@ check_installed <- function(pkg,
version <- info$ver
compare <- info$cmp

if (!any(needs_install)) {
return(invisible(NULL))
}

check_src(src, pkg)
if (is_null(src)) {
missing_srcs <- NULL
} else {
src <- ifelse(detect_na(src), pkg, src)
missing_srcs <- src[needs_install]
}

missing_pkgs <- pkg[needs_install]
missing_vers <- version[needs_install]
missing_cmps <- compare[needs_install]

if (!length(missing_pkgs)) {
return(invisible(NULL))
}

cnd <- new_error_package_not_found(
missing_pkgs,
missing_vers,
Expand All @@ -217,12 +204,6 @@ check_installed <- function(pkg,
abort("`rlib_restart_package_not_found` must be a logical value.")
}

# Can't install packages if remotes are supplied and pak is not installed
has_pak <- is_installed("pak")
if (!has_pak && !is_null(missing_srcs)) {
restart <- FALSE
}

if (!is_interactive() || !restart || any(missing_cmps %in% c("<", "<="))) {
stop(cnd)
}
Expand Down Expand Up @@ -255,9 +236,9 @@ check_installed <- function(pkg,
# Pass condition in case caller sets up an `abort` restart
invokeRestart("abort", cnd)
}
if (has_pak) {
if (is_installed("pak")) {
pkg_install <- env_get(ns_env("pak"), "pkg_install")
pkg_install(missing_srcs %||% missing_pkgs, ask = FALSE)
pkg_install(missing_pkgs, ask = FALSE)
} else {
utils::install.packages(missing_pkgs)
}
Expand Down Expand Up @@ -299,18 +280,6 @@ check_pkg_version <- function(pkg,
}
}
}
check_src <- function(src, pkg, call = caller_env()) {
if (!is_null(src)) {
if (!is_character(src, n = length(pkg), empty = FALSE)) {
msg <- sprintf(
"%s must be a character vector as long as %s.",
format_arg("src"),
format_arg("pkg")
)
abort(msg, call = call)
}
}
}

new_error_package_not_found <- function(pkg,
version = NULL,
Expand Down
5 changes: 0 additions & 5 deletions man/is_installed.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions tests/testthat/_snaps/session.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,3 @@
<error/rlang_error>
Error in `caller()`: `compare` must be one of ">", ">=", "<", or "<=".

# `src` is checked

Code
err(check_installed("foo", src = c("a", "b")))
Output
<error/rlang_error>
Error in `check_installed()`: `src` must be a character vector as long as `pkg`.
Code
err(check_installed("foo", src = 1))
Output
<error/rlang_error>
Error in `check_installed()`: `src` must be a character vector as long as `pkg`.

10 changes: 0 additions & 10 deletions tests/testthat/test-session.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,3 @@ test_that("pkg_version_info() supports `cmp`", {
err(pkg_version_info("foo", "1.0", "!="))
})
})

test_that("`src` is checked", {
expect_null(check_src(c("a", "b"), c("c", "d")))
expect_null(check_src(NULL, c("c", "d")))

expect_snapshot({
err(check_installed("foo", src = c("a", "b")))
err(check_installed("foo", src = 1))
})
})

0 comments on commit 8d9b6a9

Please sign in to comment.