insightsengineering / insightsengineering/teal.code

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

Aperta
#237 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
bug core
Lingua principale
R
Stelle
12
Fork
11
Merge medio
1g 17h
PR unite (30g)
1

Descrizione

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)

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Reproduce the reported R example and start at the get_code_dependency/get_code entry points mentioned in the report. Trace how the for-loop iterator x is recorded as a dependency, then verify that get_code(q, names = 'x') no longer extracts the temporary loop object while retaining x <- 5.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
r
Ambito
tooling
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.