Skip to contents

Checks whether code in teal_data object reproduces the stored objects.

Usage

verify(x)

Arguments

x

teal_data object

Value

Input teal_data object or error.

Details

If objects created by code in the @code slot of x are all_equal to the contents of the @env slot, the function updates the @verified slot to TRUE in the returned teal_data object. Once verified, the slot will always be set to TRUE. If the @code fails to recreate objects in teal_data@env, an error is raised.

Examples

tdata1 <- teal_data()
tdata1 <- within(tdata1, {
  a <- 1
  b <- a^5
  c <- list(x = 2)
})
verify(tdata1)
#> ✅︎ verified teal_data object
#> <environment: 0x5560814de830> [L]
#> Parent: <environment: devtools_shims>
#> Bindings:
#>  a: <dbl> [L]
#>  b: <dbl> [L]
#>  c: <named list> [L]

tdata2 <- teal_data(x1 = iris, code = "x1 <- iris")
verify(tdata2)
#> ✅︎ verified teal_data object
#> <environment: 0x55607e4839a0> [L]
#> Parent: <environment: devtools_shims>
#> Bindings:
#>  x1: <df[,5]> [L]
verify(tdata2)@verified
#> [1] TRUE
tdata2@verified
#> [1] FALSE

tdata3 <- teal_data()
tdata3 <- within(tdata3, {
  stop("error")
})
try(verify(tdata3)) # fails
#> Error : error 
#>  when evaluating qenv code:
#> stop("error")


a <- 1
b <- a + 2
c <- list(x = 2)
d <- 5
tdata4 <- teal_data(
  a = a, b = b, c = c, d = d,
  code = "a <- 1
          b <- a
          c <- list(x = 2)
          e <- 1"
)
tdata4
#> ✖ unverified teal_data object
#> <environment: 0x55607cb8e3c8> [L]
#> Parent: <environment: devtools_shims>
#> Bindings:
#>  a: <dbl> [L]
#>  b: <dbl> [L]
#>  c: <named list> [L]
#>  d: <dbl> [L]
if (FALSE) {
verify(tdata4) # fails
}