insightsengineering / insightsengineering/teal.data
[Question]: Should `get_code()` automatically extract `eval()` and `quote()` if they appear together in the code
- Dominant language
- R
- Stars
- 11
- Forks
- 9
- PR merge metrics
- No merged PRs in 30d
Description
Initially discussed in here https://github.com/insightsengineering/teal.data/pull/268#issuecomment-1906028844
For cases like below
```r
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
```r
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")
)
})
```
Contributor guide
Assessment
This issue has not been assessed yet.