diff --git a/R/deprecated.R b/R/deprecated.R index 97035fcd8..01d6f1548 100644 --- a/R/deprecated.R +++ b/R/deprecated.R @@ -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 diff --git a/tests/testthat/test-deprecated.R b/tests/testthat/test-deprecated.R new file mode 100644 index 000000000..7359e0ec7 --- /dev/null +++ b/tests/testthat/test-deprecated.R @@ -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)) + }) +})