Skip to content

Commit

Permalink
fix: allow for datanames in get_code to have backticks
Browse files Browse the repository at this point in the history
  • Loading branch information
averissimo committed Oct 22, 2024
1 parent e70bd47 commit 998eab3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions R/teal_data-get_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ setMethod("get_code", signature = "teal_data", definition = function(object, dep
checkmate::assert_character(datanames, min.len = 1L, null.ok = TRUE)
checkmate::assert_flag(deparse)

# Normalize in case special it is backticked
datanames <- gsub("^`(.*)`$", "\\1", datanames)

code <- if (!is.null(datanames)) {
get_code_dependency(object@code, datanames, ...)
} else {
Expand Down
26 changes: 26 additions & 0 deletions tests/testthat/test-get_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,32 @@ testthat::test_that("data() call is returned when data name is provided as a cha
})

testthat::describe("Backticked symbol", {
testthat::it("code can be retrieved with get_code", {
td <- teal_data() |>
within({
`%cbind%` <- function(lhs, rhs) cbind(lhs, rhs) # nolint: object_name.
iris_ds <- iris %cbind% data.frame(new_col = "new column")
})

testthat::expect_identical(
get_code(td, datanames = "%cbind%"),
"`%cbind%` <- function(lhs, rhs) cbind(lhs, rhs)"
)
})

testthat::it("code can be retrieved with get_code", {
td <- teal_data() |>
within({
`%cbind%` <- function(lhs, rhs) cbind(lhs, rhs) # nolint: object_name.
iris_ds <- iris %cbind% data.frame(new_col = "new column")
})

testthat::expect_identical(
get_code(td, datanames = "`%cbind%`"),
"`%cbind%` <- function(lhs, rhs) cbind(lhs, rhs)"
)
})

testthat::it("starting with underscore is detected in code dependency", {
td <- teal_data() |>
within({
Expand Down

0 comments on commit 998eab3

Please sign in to comment.