From 622cb09599f12c0e1827a7d603fd57927fe76fab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Revilla?= <185338939+llrs-roche@users.noreply.github.com> Date: Mon, 4 Nov 2024 14:58:52 +0100 Subject: [PATCH] Remove `new_qenv` (#222) # 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> --- NAMESPACE | 1 - NEWS.md | 2 +- R/qenv-constructor.R | 72 ++------------------------------------------ _pkgdown.yml | 1 - man/qenv.Rd | 23 ++------------ 5 files changed, 5 insertions(+), 94 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index e2d189a6..8ac246d6 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,7 +11,6 @@ export(get_env) export(get_var) export(get_warnings) export(join) -export(new_qenv) export(qenv) exportClasses(qenv) exportMethods(show) diff --git a/NEWS.md b/NEWS.md index cba04a27..c67be508 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/qenv-constructor.R b/R/qenv-constructor.R index fa2fa333..504b1259 100644 --- a/R/qenv-constructor.R +++ b/R/qenv-constructor.R @@ -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() @@ -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) - } -) diff --git a/_pkgdown.yml b/_pkgdown.yml index 3b151760..8e38b126 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -34,7 +34,6 @@ reference: - get_var - get_warnings - join - - new_qenv - qenv - show,qenv-method - within.qenv diff --git a/man/qenv.Rd b/man/qenv.Rd index 4d382246..232c5506 100644 --- a/man/qenv.Rd +++ b/man/qenv.Rd @@ -3,12 +3,6 @@ % R/qenv-get_code.R, R/qenv-within.R \name{qenv} \alias{qenv} -\alias{new_qenv} -\alias{new_qenv,environment,expression-method} -\alias{new_qenv,environment,character-method} -\alias{new_qenv,environment,language-method} -\alias{new_qenv,environment,missing-method} -\alias{new_qenv,missing,missing-method} \alias{eval_code} \alias{eval_code,qenv,character-method} \alias{eval_code,qenv,language-method} @@ -22,8 +16,6 @@ \usage{ qenv() -new_qenv(env = new.env(parent = parent.env(.GlobalEnv)), code = character()) - eval_code(object, code) get_code(object, deparse = TRUE, names = NULL, ...) @@ -31,13 +23,10 @@ get_code(object, deparse = TRUE, names = NULL, ...) \method{within}{qenv}(data, expr, ...) } \arguments{ -\item{env}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} (\code{environment}) -Environment being a result of the \code{code} evaluation.} +\item{object}{(\code{qenv})} \item{code}{(\code{character} or \code{language}) code to evaluate. If \code{character}, comments are retained.} -\item{object}{(\code{qenv})} - \item{deparse}{(\code{logical(1)}) flag specifying whether to return code as \code{character} or \code{expression}.} \item{names}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} (\code{character}) vector of object names to return the code for. @@ -50,7 +39,7 @@ For more details see the "Extracting dataset-specific code" section.} \item{expr}{(\code{expression}) to evaluate. Must be inline code, see \verb{Using language objects...}} } \value{ -\code{qenv} and \code{new_qenv} return a \code{qenv} object. +Returns a \code{qenv} object. \code{eval_code} returns a \code{qenv} object with \code{expr} evaluated or \code{qenv.error} if evaluation fails. @@ -67,9 +56,6 @@ Create a \code{qenv} object and evaluate code in it to track code history. \code{qenv()} instantiates a \code{qenv} with an empty environment. Any changes must be made by evaluating code in it with \code{eval_code} or \code{within}, thereby ensuring reproducibility. -\code{new_qenv()} (\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} and not recommended) -can instantiate a \code{qenv} object with data in the environment and code registered. - \code{eval_code} evaluates given code in the \code{qenv} environment and appends it to the \code{code} slot. Thus, if the \code{qenv} had been instantiated empty, contents of the environment are always a result of the stored code. @@ -162,11 +148,6 @@ Only single \code{expression}s will work and substitution is not available. See # create empty qenv qenv() -# 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") - # evaluate code in qenv q <- qenv() q <- eval_code(q, "a <- 1")