-
-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: [WARN] In ‘sym_cond > ass_cond’: longer object length is not a multiple of shorter object length #235
Comments
Smaller reproducible example2 of the problem From: pkgload::load_all("../teal.code")
#> ℹ Loading teal.code
testthat::test_that("", {
q <- within(qenv(), {
a <- 1
b <- 2
}) |> within({
for (x in c(1, 2)) {
b <- a
b <- b + a + 1
}
})
testthat::expect_setequal(
strsplit(get_code(q, names = "b"), "\n")[[1]],
c(
"a <- 1",
"b <- 2",
"for (x in c(1, 2)) {",
" b <- a",
" b <- b + a + 1",
"}"
)
)
})
#> ── Warning: ───────────────────────────────────────────────────────────────────
#> longer object length is not a multiple of shorter object length
#> Backtrace:
#> ▆
#> 1. ├─base::within(...)
#> 2. └─teal.code:::within.qenv(...)
#> 3. ├─teal.code::eval_code(object = data, code = as.expression(calls)) at teal.code/R/qenv-within.R:70:3
#> 4. └─teal.code::eval_code(object = data, code = as.expression(calls)) at teal.code/R/qenv-eval_code.R:31:25
#> 5. └─base::Reduce(eval_code, init = object, x = code) at teal.code/R/qenv-eval_code.R:102:5
#> 6. ├─teal.code (local) f(init, x[[i]])
#> 7. └─teal.code (local) f(init, x[[i]]) at teal.code/R/qenv-eval_code.R:31:25
#> 8. ├─teal.code::eval_code(...) at teal.code/R/qenv-eval_code.R:94:3
#> 9. └─teal.code::eval_code(...) at teal.code/R/qenv-eval_code.R:31:25
#> 10. └─teal.code:::extract_dependency(current_call) at teal.code/R/qenv-eval_code.R:85:5
#> 11. └─teal.code:::extract_occurrence(reordered_pd[[1]]) at teal.code/R/utils-get_code_dependency.R:332:5 Created on 2024-11-20 with reprex v2.1.1 pkgload::load_all("/home/averissimo/work/roche🟦/packages📦/teal.code")
#> ℹ Loading teal.code
testthat::test_that("", {
q <- within(qenv(), {
a <- 1
b <- 2
}) |> eval_code("
for (x in c(1, 2)) {
b <- a
b <- b + a + 1
b + 3 -> b # yada
}
")
})
#> ── Error: ─────────────────────────────────────────────────────────────────────
#> Error in `if (unique(x$text[ass_cond]) == "->") {
#> sym_cond <- rev(sym_cond)
#> }`: the condition has length > 1
#> Backtrace:
#> ▆
#> 1. ├─teal.code::eval_code(...)
#> 2. └─teal.code::eval_code(...) at teal.code/R/qenv-eval_code.R:31:25
#> 3. └─teal.code:::extract_dependency(current_call) at teal.code/R/qenv-eval_code.R:85:5
#> 4. └─teal.code:::extract_occurrence(reordered_pd[[1]]) at teal.code/R/utils-get_code_dependency.R:332:5
#> Error:
#> ! Test failed |
Related problem: pkgload::load_all("/home/averissimo/work/roche🟦/packages📦/teal.code")
#> ℹ Loading teal.code
testthat::test_that("", {
q <- within(qenv(), {
a <- 1
b <- 2
}) |> within({
for (x in c(1, 2)) {
b <- a
b <- b + a + 1
b + 3 -> b
}
})
testthat::expect_setequal(
strsplit(get_code(q, names = "b"), "\n")[[1]],
c(
"a <- 1",
"b <- 2",
"for (x in c(1, 2)) {",
" b <- a",
" b <- b + a + 1",
" b + 3 -> b",
"}"
)
)
})
#> ── Failure: ───────────────────────────────────────────────────────────────────
#> strsplit(get_code(q, names = "b"), "\n")[[1]] (`actual`) and c(...) (`expected`) don't have the same values.
#> * Only in `actual`: "a <- 1", "for (x in c(1, 2)) {", " b <- a", " b <- b + a + 1", " b + 3 -> b", "}"
#> Error:
#> ! Test failed Created on 2024-11-20 with reprex v2.1.1 |
Here's a better snippet that shows the problem where the pkgload::load_all("../teal.code")
#> ℹ Loading teal.code
code <- "
some_other_dataset <- mtcars
original_dataset <- iris[, 1:4]
count <- 1
for (x in colnames(original_dataset)) {
original_dataset[, x] <- original_dataset[, x] * 2
count <- count + 1
}
output <- rlang::list2(x = original_dataset)
"
q <- eval_code(qenv(), code)
#> Warning in sym_cond > ass_cond: longer object length is not a multiple of
#> shorter object length
q |> get_code() |> cat()
#>
#> some_other_dataset <- mtcars
#> original_dataset <- iris[, 1:4]
#> count <- 1
#> for (x in colnames(original_dataset)) {
#> original_dataset[, x] <- original_dataset[, x] * 2
#> count <- count + 1
#> }
#> output <- rlang::list2(x = original_dataset)
q |> get_code(names = "output") |> cat()
#> original_dataset <- iris[, 1:4]
#> output <- rlang::list2(x = original_dataset)
q$output$name[1,1]
#> NULL
iris[1, 1]
#> [1] 5.1 Created on 2024-11-27 with reprex v2.1.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Potentially caused by
teal.code:::get_code_dependency
What happened?
When running below on this branch insightsengineering/teal.modules.general#795
sessionInfo()
No response
Relevant log output
No response
Code of Conduct
Contribution Guidelines
Security Policy
The text was updated successfully, but these errors were encountered: