insightsengineering / teal.data

Data model for teal applications
https://insightsengineering.github.io/teal.data/
Other
9 stars 8 forks source link

[Question]: Should `get_code()` automatically extract `eval()` and `quote()` if they appear together in the code #270

Open m7pr opened 9 months ago

m7pr commented 9 months ago

Initially discussed in here https://github.com/insightsengineering/teal.data/pull/268#issuecomment-1906028844

For cases like below

testthat::test_that("get_code does not break if code uses quote", {
  code <- c(
    "expr <- quote(x <- x + 1)",
    "x <- 0",
    "eval(expr)"
  )
  tdata <- eval_code(teal_data(), code)
  testthat::expect_identical(
    get_code(tdata, datanames = "x"),
    code[2]
  )
})

Should get_code return whole code vector, or only code[2]. We know that x is used in quote which is later evaluated. So far we can overcome this with # @linksto x tag

testthat::test_that("get_code does not break if code uses quote", {
  code <- c(
    "expr <- quote(x <- x + 1) #@linksto x",
    "x <- 0",
    "eval(expr) #@linksto x"
  )
  tdata <- eval_code(teal_data(), code)
  testthat::expect_identical(
    get_code(tdata, datanames = "x"),
    paste(gsub(" #@linksto x", "", code, fixed = TRUE), collapse = "\n")
  )
})
averissimo commented 9 months ago

I think we should draw the line somewhere and just return the whole code vector for those cases. For me eval is one of those.

Otherwise, we enter inception territory trying to support ALL the edge cases.