Skip to content

Commit

Permalink
Fixes datanames() assignment and re-adds test for deprecated functi…
Browse files Browse the repository at this point in the history
…on (#350)

# Pull Request

Part of #333 

#### Changes description

- Method was incorrectly overwriting the `teal_data` object with their
own names
- Adds test that will continue to test the functionality until it's
removed from the framework

Co-authored-by: Marcin <[email protected]>
  • Loading branch information
averissimo and m7pr authored Nov 11, 2024
1 parent 169180d commit c67d840
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/deprecated.R
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ datanames <- function(x) {
"`datanames<-`()",
details = "invalid to use `datanames()<-` or `names()<-` on an object of class `teal_data`. See ?names.teal_data"
)
names(x)
x
}

#' @rdname datanames
Expand Down
34 changes: 34 additions & 0 deletions tests/testthat/test-deprecated.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
testthat::describe("datanames deprecation: ", {
testthat::it("setter does nothing to object", {
td <- teal_data() |>
within({
iris <- iris
mtcars <- mtcars
})

# ignore deprecation warnings
withr::local_options(lifecycle_verbosity = "quiet")
datanames(td) <- c("mtcars")

testthat::expect_equal(
td,
teal_data() |>
within({
iris <- iris
mtcars <- mtcars
})
)
})

testthat::it("getter returns same as `names()`", {
td <- teal_data() |>
within({
iris <- iris
mtcars <- mtcars
})

# ignore deprecation warnings
withr::local_options(lifecycle_verbosity = "quiet")
testthat::expect_setequal(datanames(td), names(td))
})
})

0 comments on commit c67d840

Please sign in to comment.