Skip to content

Commit ba1a552

Browse files
committed
fix for verified/unverified teal_data
1 parent 2a0f49b commit ba1a552

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

R/utils-get_code_dependency.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@
1919
#'
2020
#' @param code `character` with the code.
2121
#' @param names `character` vector of object names.
22-
#' @param check_names `logical(1)` flag specifying if a warning for non-existing names should be displayed.
22+
#' @param check_code_names `logical(1)` flag specifying if a warning for non-existing names should be displayed.
2323
#'
2424
#' @return Character vector, a subset of `code`.
2525
#' Note that subsetting is actually done on the calls `code`, not necessarily on the elements of the vector.
2626
#'
2727
#' @keywords internal
28-
get_code_dependency <- function(code, names, check_names = TRUE) {
28+
get_code_dependency <- function(code, names, check_code_names = TRUE) {
2929
checkmate::assert_list(code, "character")
3030
checkmate::assert_character(names, any.missing = FALSE)
3131

3232
graph <- lapply(code, attr, "dependency")
3333

34-
if (check_names) {
34+
if (check_code_names) {
3535
symbols <- unlist(lapply(graph, function(call) {
3636
ind <- match("<-", call, nomatch = length(call) + 1L)
3737
call[seq_len(ind - 1L)]

man/get_code_dependency.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-qenv_extract.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,28 @@ testthat::test_that("`[.` warns and subsets to existing if some names not presen
4141
)
4242
})
4343

44+
testthat::test_that("`[.` warns if name is in code but not in env", {
45+
data <- within(qenv(), {
46+
a <- 1
47+
b <- 2
48+
c <- 3
49+
d <- 4
50+
})
51+
data@code <- data@code[1]
52+
testthat::expect_warning(data[c("a", "b", "c")])
53+
})
54+
55+
testthat::test_that("`[.` doesn't warn if name is in code but not in env (secret feature for unverified teal_data)", {
56+
data <- within(qenv(), {
57+
a <- 1
58+
b <- 2
59+
c <- 3
60+
d <- 4
61+
})
62+
data@code <- data@code[1]
63+
testthat::expect_silent(data[c("a", "b", "c"), check_code_names = FALSE])
64+
})
65+
4466
testthat::test_that("`[.` subsets environment and code to specified object names", {
4567
q <- qenv()
4668
code <- c("x<-1", "a<-1;b<-2")

0 commit comments

Comments
 (0)