Skip to content

Commit

Permalink
Deprecate env_browse() and env_is_browsed()
Browse files Browse the repository at this point in the history
Closes #1727
  • Loading branch information
lionel- committed Jul 2, 2024
1 parent 5634e96 commit 6f102ce
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 42 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Suggests:
Enhances:
winch
Encoding: UTF-8
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Roxygen: list(markdown = TRUE)
URL: https://rlang.r-lib.org, https://github.com/r-lib/rlang
BugReports: https://github.com/r-lib/rlang/issues
Expand Down
7 changes: 5 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# rlang (development version)

* `env_browse()` and `env_is_browsed()` are now defunct as they require an API
that is no longer available to packages (#1727).

* `env_unlock()` is now defunct because recent versions of R no long
make it possible to unlock an environment. Make sure to use an up-to-date
version of pkgload (>= 1.4.0) following this change.
make it possible to unlock an environment (#1705). Make sure to use an
up-to-date version of pkgload (>= 1.4.0) following this change.


# rlang 1.1.4
Expand Down
10 changes: 6 additions & 4 deletions R/env.R
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,8 @@ env_is_locked <- function(env) {
env_unlock <- function(env) {
msg <- "`env_unlock()` is defunct as of rlang 1.1.5"

old_pkgload_running <-
"pkgload" %in% loadedNamespaces() &&
old_pkgload_running <-
"pkgload" %in% loadedNamespaces() &&
some(sys.frames(), function(env) identical(topenv(env), ns_env("pkgload"))) &&
utils::packageVersion("pkgload") <= "1.3.4"

Expand Down Expand Up @@ -754,6 +754,8 @@ str.rlang_envs <- function(object, ...) {
#'
#' @description
#'
#' `r lifecycle::badge("defunct")`
#'
#' * `env_browse(env)` is equivalent to evaluating `browser()` in
#' `env`. It persistently sets the environment for step-debugging.
#' Supply `value = FALSE` to disable browsing.
Expand All @@ -767,12 +769,12 @@ str.rlang_envs <- function(object, ...) {
#' `env_is_browsed()` (a logical), invisibly.
#' @export
env_browse <- function(env, value = TRUE) {
invisible(.Call(ffi_env_browse, env, value))
abort("`env_browse()` is defunct as of rlang 1.2.0 because R no longer supports it")
}
#' @rdname env_browse
#' @export
env_is_browsed <- function(env) {
.Call(ffi_env_is_browsed, env)
abort("`env_is_browsed()` is defunct as of rlang 1.2.0 because R no longer supports it")
}

#' Is frame environment user facing?
Expand Down
1 change: 1 addition & 0 deletions man/env_browse.Rd

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

20 changes: 0 additions & 20 deletions src/internal/exported.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,26 +511,6 @@ r_obj* ffi_env_bind_list(r_obj* env, r_obj* names, r_obj* data) {
return r_null;
}

r_obj* ffi_env_browse(r_obj* env, r_obj* value) {
if (r_typeof(env) != R_TYPE_environment) {
r_abort("`env` must be an environment.");
}
if (!r_is_bool(value)) {
r_abort("`value` must be a single logical value.");
}

r_obj* old = r_lgl(RDEBUG(env));
SET_RDEBUG(env, r_lgl_get(value, 0));
return old;
}

r_obj* ffi_env_is_browsed(r_obj* env) {
if (r_typeof(env) != R_TYPE_environment) {
r_abort("`env` must be an environment.");
}
return r_lgl(RDEBUG(env));
}

r_obj* ffi_ns_registry_env(void) {
return R_NamespaceRegistry;
}
Expand Down
2 changes: 0 additions & 2 deletions src/internal/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ static const R_CallMethodDef r_callables[] = {
{"ffi_env_bind", (DL_FUNC) &ffi_env_bind, 5},
{"ffi_env_bind_list", (DL_FUNC) &ffi_env_bind_list, 3},
{"ffi_env_binding_types", (DL_FUNC) &r_env_binding_types, 2},
{"ffi_env_browse", (DL_FUNC) &ffi_env_browse, 2},
{"ffi_env_clone", (DL_FUNC) &r_env_clone, 2},
{"ffi_env_coalesce", (DL_FUNC) &ffi_env_coalesce, 2},
{"ffi_env_frame", (DL_FUNC) &ffi_env_frame, 1},
Expand All @@ -83,7 +82,6 @@ static const R_CallMethodDef r_callables[] = {
{"ffi_env_has", (DL_FUNC) &ffi_env_has, 3},
{"ffi_env_hash_table", (DL_FUNC) &ffi_env_hash_table, 1},
{"ffi_env_inherits", (DL_FUNC) &ffi_env_inherits, 2},
{"ffi_env_is_browsed", (DL_FUNC) &ffi_env_is_browsed, 1},
{"ffi_env_poke", (DL_FUNC) &ffi_env_poke, 5},
{"ffi_env_poke_parent", (DL_FUNC) &ffi_env_poke_parent, 2},
{"ffi_env_unbind", (DL_FUNC) &ffi_env_unbind, 3},
Expand Down
13 changes: 0 additions & 13 deletions tests/testthat/test-env.R
Original file line number Diff line number Diff line change
Expand Up @@ -519,19 +519,6 @@ test_that("get_env() returns the base namespace for primitive functions (r-lib/d
expect_identical(get_env(is.null), ns_env("base"))
})

test_that("can browse environments", {
env <- env()
expect_false(env_is_browsed(env))

old <- env_browse(env)
expect_false(old)
expect_true(env_is_browsed(env))

old <- env_browse(env, FALSE)
expect_true(old)
expect_false(env_is_browsed(env))
})

test_that("env_has() doesn't force active bindings (#1292)", {
e <- env()
env_bind_active(e, active = function() abort("forced"))
Expand Down

0 comments on commit 6f102ce

Please sign in to comment.