Skip to content

Commit

Permalink
remove verify-warning from the code (#334)
Browse files Browse the repository at this point in the history
linking to the discussion

insightsengineering/teal#1342 (comment)

- removed verification-warning message from get_code 
- ~~added is_verified method to possibly handle `@verified == FALSE` by
external process. I'm fine to use `@verified` directly in `teal` - I'm
happy also to remove `is_verified` if suggested in review.~~
  • Loading branch information
gogonzo committed Sep 26, 2024
1 parent 98a58ad commit bd19dea
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 24 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
- do not allow to set a dataset name that do not exist in `teal_data` environment.
- `teal_data` no longer set default `datanames()` based on `join_keys` names - it uses only data names.

### Miscellaneous

- `get_code` no longer adds `warning` message about failed verification.

# teal.data 0.6.0

### Enhancements
Expand Down
5 changes: 0 additions & 5 deletions R/teal_data-get_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#'
#' Retrieve code stored in `@code`, which (in principle) can be used to recreate all objects found in `@env`.
#' Use `datanames` to limit the code to one or more of the datasets enumerated in `@datanames`.
#' If the code has not passed verification (with [`verify()`]), a warning will be prepended.
#'
#' @section Extracting dataset-specific code:
#' When `datanames` is specified, the code returned will be limited to the lines needed to _create_
Expand Down Expand Up @@ -114,10 +113,6 @@ setMethod("get_code", signature = "teal_data", definition = function(object, dep
object@code
}

if (!object@verified) {
code <- c("warning('Code was not verified for reproducibility.')", code)
}

if (deparse) {
if (length(code) == 0) {
code
Expand Down
1 change: 0 additions & 1 deletion man/get_code.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 5 additions & 16 deletions tests/testthat/test-get_code.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
warning_message <- "warning('Code was not verified for reproducibility.')"

testthat::test_that("handles empty @code slot", {
testthat::expect_identical(
get_code(teal_data(a = 1, code = character(0)), datanames = "a"),
warning_message
character(0)
)
testthat::expect_identical(
get_code(teal_data(a = 1, code = ""), datanames = "a"),
paste0(warning_message, "\n")
""
)
})

Expand All @@ -20,7 +18,7 @@ testthat::test_that("handles the code without symbols on rhs", {

testthat::expect_identical(
get_code(teal_data(a = 5, code = code), datanames = "a"),
paste(warning_message, "a <- 5", sep = "\n")
"a <- 5"
)
})

Expand All @@ -29,7 +27,7 @@ testthat::test_that("handles the code included in curly brackets", {

testthat::expect_identical(
get_code(teal_data(a = 5, code = code), datanames = "a"),
paste(warning_message, "a <- 5", sep = "\n")
"a <- 5"
)
})

Expand Down Expand Up @@ -545,11 +543,7 @@ testthat::test_that("detects occurrence of a function definition with a @linksto
tdata <- teal_data(code = code)
testthat::expect_identical(
get_code(tdata, datanames = "x"),
paste(
warning_message,
"foo <- function() {\n env <- parent.frame()\n env$x <- 0\n}\nfoo()",
sep = "\n"
)
"foo <- function() {\n env <- parent.frame()\n env$x <- 0\n}\nfoo()"
)
})
# $ ---------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -608,7 +602,6 @@ testthat::test_that("understands @ usage and do not treat rhs of @ as objects (o
testthat::expect_identical(
get_code(tdata, datanames = "x"),
paste(
warning_message,
'setClass("aclass", slots = c(a = "numeric", x = "numeric", y = "numeric"))',
'x <- new("aclass", a = 1:3, x = 1:3, y = 1:3)',
sep = "\n"
Expand All @@ -617,7 +610,6 @@ testthat::test_that("understands @ usage and do not treat rhs of @ as objects (o
testthat::expect_identical(
get_code(tdata, datanames = "a"),
paste(
warning_message,
'setClass("aclass", slots = c(a = "numeric", x = "numeric", y = "numeric"))',
'x <- new("aclass", a = 1:3, x = 1:3, y = 1:3)',
'a <- new("aclass", a = 1:3, x = 1:3, y = 1:3)',
Expand Down Expand Up @@ -646,7 +638,6 @@ testthat::test_that("library() and require() are always returned", {
testthat::expect_identical(
get_code(tdata, datanames = "x"),
paste(
warning_message,
"library(random.cdisc.data)",
"require(dplyr)",
"library(MultiAssayExperiment)",
Expand All @@ -672,7 +663,6 @@ testthat::test_that("data() call is returned when data name is provided as is",
testthat::expect_identical(
get_code(tdata, datanames = "x"),
paste(
warning_message,
"library(random.cdisc.data)",
"require(dplyr)",
"library(MultiAssayExperiment)",
Expand All @@ -696,7 +686,6 @@ testthat::test_that("data() call is returned when data name is provided as a cha
testthat::expect_identical(
get_code(tdata, datanames = "z"),
paste(
warning_message,
"library(random.cdisc.data)",
"require(dplyr)",
"library(MultiAssayExperiment)",
Expand Down
3 changes: 1 addition & 2 deletions vignettes/teal-data-reproducibility.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ data_with_data <- teal_data(i = head(iris), code = "i <- head(iris)")
data_with_data # is unverified
data_with_data <- within(data_with_data, i$rand <- sample(nrow(i)))
data_with_data # remains unverified
cat(get_code(data_with_data)) # warning is prepended
```

### Verification process
Expand All @@ -69,7 +68,7 @@ data_right <- teal_data(
data <- data.frame(x = 11:20)
data$id <- seq_len(nrow(data))
})
)
) # is unverified
(data_right_verified <- verify(data_right)) # returns verified object
```

Expand Down

0 comments on commit bd19dea

Please sign in to comment.