Skip to content

Commit

Permalink
Remove new_qenv (#222)
Browse files Browse the repository at this point in the history
# Pull Request

As commented on #215, it was hard to see a pattern on what to do when
deprecating functions.
Based on @m7pr feedback I deleted the help page and the code (generic and methods).
teal.gallery and tlg-catalog were searched and no usage was found (and deprectae_warn, would have warned). 

Fixes #215

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
llrs-roche and github-actions[bot] authored Nov 4, 2024
1 parent 86aa265 commit 622cb09
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 94 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export(get_env)
export(get_var)
export(get_warnings)
export(join)
export(new_qenv)
export(qenv)
exportClasses(qenv)
exportMethods(show)
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

### Breaking Change

* `qenv` objects should now be created with `qenv()` rather than `new_qenv()`. The new constructor always creates an empty object. `new_qenv` is now deprecated.
* `qenv` objects should now be created with `qenv()` rather than `new_qenv()` (which has been removed). The new constructor always creates an empty object.

### Miscellaneous

Expand Down
72 changes: 2 additions & 70 deletions R/qenv-constructor.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
#' `qenv()` instantiates a `qenv` with an empty environment.
#' Any changes must be made by evaluating code in it with `eval_code` or `within`, thereby ensuring reproducibility.
#'
#' `new_qenv()` (`r badge("deprecated")` and not recommended)
#' can instantiate a `qenv` object with data in the environment and code registered.
#'
#' @name qenv
#'
#' @return `qenv` and `new_qenv` return a `qenv` object.
#' @return Returns a `qenv` object.
#'
#' @seealso [`base::within()`], [`get_var()`], [`get_env()`], [`get_warnings()`], [`join()`], [`concat()`]
#' @examples
#' # create empty qenv
#' qenv()
Expand All @@ -27,69 +25,3 @@ qenv <- function() {
lockEnvironment(q_env, bindings = TRUE)
methods::new("qenv", env = q_env)
}


#' @param code `r badge("deprecated")`
#' (`character(1)` or `language`) code to evaluate. Accepts and stores comments also.
#' @param env `r badge("deprecated")` (`environment`)
#' Environment being a result of the `code` evaluation.
#'
#' @examples
#' # create qenv with data and code (deprecated)
#' new_qenv(env = list2env(list(a = 1)), code = quote(a <- 1))
#' new_qenv(env = list2env(list(a = 1)), code = parse(text = "a <- 1", keep.source = TRUE))
#' new_qenv(env = list2env(list(a = 1)), code = "a <- 1")
#'
#' @rdname qenv
#' @aliases new_qenv,environment,expression-method
#' @aliases new_qenv,environment,character-method
#' @aliases new_qenv,environment,language-method
#' @aliases new_qenv,environment,missing-method
#' @aliases new_qenv,missing,missing-method
#'
#' @seealso [`base::within()`], [`get_var()`], [`get_env()`], [`get_warnings()`], [`join()`], [`concat()`]
#'
#' @export
setGeneric("new_qenv", function(env = new.env(parent = parent.env(.GlobalEnv)), code = character()) {
lifecycle::deprecate_warn(when = " 0.5.0", what = "new_qenv()", with = "qenv()", always = TRUE)
standardGeneric("new_qenv")
})

setMethod(
"new_qenv",
signature = c(env = "environment", code = "expression"),
function(env, code) {
new_qenv(env, paste(lang2calls(code), collapse = "\n"))
}
)

setMethod(
"new_qenv",
signature = c(env = "environment", code = "character"),
function(env, code) {
new_env <- rlang::env_clone(env, parent = parent.env(.GlobalEnv))
lockEnvironment(new_env, bindings = TRUE)
if (length(code) > 0) code <- paste(code, collapse = "\n")
id <- sample.int(.Machine$integer.max, size = length(code))
methods::new(
"qenv",
env = new_env, code = code, warnings = rep("", length(code)), messages = rep("", length(code)), id = id
)
}
)

setMethod(
"new_qenv",
signature = c(env = "environment", code = "language"),
function(env, code) {
new_qenv(env = env, code = paste(lang2calls(code), collapse = "\n"))
}
)

setMethod(
"new_qenv",
signature = c(code = "missing", env = "missing"),
function(env, code) {
new_qenv(env = env, code = code)
}
)
1 change: 0 additions & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ reference:
- get_var
- get_warnings
- join
- new_qenv
- qenv
- show,qenv-method
- within.qenv
23 changes: 2 additions & 21 deletions man/qenv.Rd

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

0 comments on commit 622cb09

Please sign in to comment.