Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
m7pr opened this issue Jan 23, 2024 · 1 comment

Comments

@m7pr
Copy link
Contributor

m7pr commented Jan 23, 2024

Initially discussed in here #268 (comment)

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")
  )
})
@m7pr m7pr changed the title [Question]: Should get_code_dependency() automatically extract eval() and quote() if they appear together in the code [Question]: Should get_code() automatically extract eval() and quote() if they appear together in the code Jan 23, 2024
@averissimo
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants