From e932ea71f21d556dff5770d428c781935bead2e8 Mon Sep 17 00:00:00 2001 From: Nikolas Burkoff Date: Thu, 22 Sep 2022 11:48:33 +0100 Subject: [PATCH 1/2] remove list option for constructor --- R/qenv-constructor.R | 31 -------------------------- man/new_qenv.Rd | 3 --- tests/testthat/test-qenv_constructor.R | 6 ----- 3 files changed, 40 deletions(-) diff --git a/R/qenv-constructor.R b/R/qenv-constructor.R index f5cc1cb0..eeb5f927 100644 --- a/R/qenv-constructor.R +++ b/R/qenv-constructor.R @@ -52,37 +52,6 @@ setMethod( } ) -#' @rdname new_qenv -#' @export -setMethod( - "new_qenv", - signature = c(env = "list"), - function(env, code) { - if (!missing(code)) { - warning( - "`code` argument is ignored when creating qenv from the list.", - "\nPlease pass the code througn attr(, 'code')" - ) - } - - code <- attr(env, "code") # named - if (length(code) == 0) { - stop("To create the qenv from the list it must contain 'code' attribute.") - } - - if (checkmate::test_list(env, "reactive")) { - env <- lapply(env, function(x) { - if (inherits(x, "reactive")) { - x() - } else { - x - } - }) - } - new_qenv(env = list2env(env), code = code) - } -) - #' @rdname new_qenv #' @export setMethod( diff --git a/man/new_qenv.Rd b/man/new_qenv.Rd index cd592a51..ef0ace7d 100644 --- a/man/new_qenv.Rd +++ b/man/new_qenv.Rd @@ -5,7 +5,6 @@ \alias{new_qenv,environment,expression-method} \alias{new_qenv,environment,character-method} \alias{new_qenv,environment,language-method} -\alias{new_qenv,list,ANY-method} \alias{new_qenv,missing,missing-method} \title{Initialize \code{qenv} object} \usage{ @@ -17,8 +16,6 @@ new_qenv(env = new.env(parent = parent.env(.GlobalEnv)), code = expression()) \S4method{new_qenv}{environment,language}(env = new.env(parent = parent.env(.GlobalEnv)), code = expression()) -\S4method{new_qenv}{list,ANY}(env = new.env(parent = parent.env(.GlobalEnv)), code = expression()) - \S4method{new_qenv}{missing,missing}(env = new.env(parent = parent.env(.GlobalEnv)), code = expression()) } \arguments{ diff --git a/tests/testthat/test-qenv_constructor.R b/tests/testthat/test-qenv_constructor.R index d7e2d33c..852861d2 100644 --- a/tests/testthat/test-qenv_constructor.R +++ b/tests/testthat/test-qenv_constructor.R @@ -54,12 +54,6 @@ testthat::test_that("new_qenv works with code being quoted expression", { testthat::expect_true(checkmate::test_int(q@id)) }) -testthat::test_that("code argument is ignored in new_qenv and throws a warning", { - env <- list(iris1 = iris) - attr(env, "code") <- quote(iris1 <- iris) - testthat::expect_warning(new_qenv(env = env, iris1 <- iris)) -}) - testthat::test_that("new_qenv works with code being length > 1", { env <- new.env() env$iris1 <- iris From 5b0eafcdb77c0bdbe9fba67fa3a15240bc2a02f2 Mon Sep 17 00:00:00 2001 From: Nikolas Burkoff Date: Thu, 22 Sep 2022 11:55:37 +0100 Subject: [PATCH 2/2] change error message --- R/qenv-join.R | 8 ++++---- tests/testthat/test-qenv_join.R | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/R/qenv-join.R b/R/qenv-join.R index 7b97f21d..40e03bc0 100644 --- a/R/qenv-join.R +++ b/R/qenv-join.R @@ -100,14 +100,14 @@ setMethod("join", signature = c("qenv", "qenv.error"), function(x, y) { TRUE } else if (!identical(shared_in_x, shared_in_y)) { paste( - "The common code of joined objects doesn't have the same indices. It means that `x` and `y`", - "can't be joined together as it's impossible to determine the evaluation's order.", + "The common shared code of the qenvs does not occur in the same position in both qenv objects", + "so they cannot be joined together as it's impossible to determine the evaluation's order.", collapse = "" ) } else { paste( - "The common code of joined object does not start from index = 1.", - "It means that joined object(x) has some extra code elements before.", + "There is code in the qenv objects before their common shared code", + "which means these objects cannot be joined.", collapse = "" ) } diff --git a/tests/testthat/test-qenv_join.R b/tests/testthat/test-qenv_join.R index c5a22382..0ffd3236 100644 --- a/tests/testthat/test-qenv_join.R +++ b/tests/testthat/test-qenv_join.R @@ -139,8 +139,8 @@ testthat::test_that( q_common <- new_qenv(quote(c1 <- 3), env = list2env(list(c1 = 3))) q1 <- join(q1, q_common) q2 <- join(q2, q_common) - testthat::expect_match(.check_joinable(q1, q2), "start from index = 1") - testthat::expect_error(join(q1, q2), "start from index = 1") + testthat::expect_match(.check_joinable(q1, q2), "these objects cannot be joined") + testthat::expect_error(join(q1, q2), "these objects cannot be joined") } ) @@ -152,8 +152,8 @@ testthat::test_that("qenv objects are not mergable if they have multiple common q1 <- join(q1, q_common2) # c1, a1, c2 q2 <- join(q_common1, q_common2) # c1, c2 - testthat::expect_match(.check_joinable(q1, q2), "doesn't have the same indices") - testthat::expect_error(join(q1, q2), "doesn't have the same indices") + testthat::expect_match(.check_joinable(q1, q2), "it's impossible to determine the evaluation's order") + testthat::expect_error(join(q1, q2), "it's impossible to determine the evaluation's order") })