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: 0x56037b8b3150> [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: 0x560375df1610> [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: 0x560375c43bf0> [L]
#> Parent: <environment: devtools_shims>
#> Bindings:
#>  a: <dbl> [L]
#>  b: <dbl> [L]
#>  c: <named list> [L]
#>  d: <dbl> [L]
try(verify(tdata4)) # fails
#> Error : Code verification failed.
#> Object(s) recreated with code that have different structure in tdata4:
#>   • b
#> Object(s) not created with code that exist in tdata4:
#>   • d
#> Object(s) created with code that do not exist in tdata4:
#>   • e