insightsengineering / insightsengineering/teal.code

[Bug]: Iterator of the for loop is treated as an object in get_code_dependency

Open
#237 2 comments 0 reactions 0 assignees View on GitHub
bug core
Dominant language
R
Stars
12
Forks
11
Avg merge
1d 17h
Merged PRs (30d)
1

Description

If object is treated as an iterator in a `for` loop, like `x` below, then `get_code` treats this case as this object created in this `for` loop, hence even though it's a temporary object (just for the time of the `for` loop execution) it gets extracted in the `get_code`

``` r
library(teal.code)
q <- within(qenv(), {
a <- 1
b <- 2
}) |> within({
for (x in c(1, 2)) {
b <- a
b <- b + a + 1
b + 3 -> b
}
}) |> within({
x <- 5
})

get_code(q, names = 'x') |> cat()
#> a <- 1
#> b <- 2
#> for (x in c(1, 2)) {
#> b <- a
#> b <- b + a + 1
#> b <- b + 3
#> }
#> x <- 5
```

Created on 2024-11-27 with [reprex v2.1.1](https://reprex.tidyverse.org)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.