Skip to content

Commit

Permalink
Improve error message (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolas Burkoff authored Sep 23, 2022
1 parent fcff4cb commit 5a2eef1
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 48 deletions.
31 changes: 0 additions & 31 deletions R/qenv-constructor.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(<list>, '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(
Expand Down
8 changes: 4 additions & 4 deletions R/qenv-join.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
)
}
Expand Down
3 changes: 0 additions & 3 deletions man/new_qenv.Rd

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

6 changes: 0 additions & 6 deletions tests/testthat/test-qenv_constructor.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-qenv_join.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
)

Expand All @@ -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")
})


Expand Down

0 comments on commit 5a2eef1

Please sign in to comment.