findGlobals(): Distinguish between functions and non-functions
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
Direzione di ricerca
Inizia leggendo gli entry point esistenti findGlobals() e globalsOf() e seguendo il modo in cui vengono classificati i simboli nelle chiamate quotate. Confronta i simboli in posizione di funzione con i simboli in posizione di valore usando gli esempi sum(), sum, sum + 2 e -sum dell’issue. Il lavoro è completato quando la chiamata di funzione viene risolta in base::sum() senza trattare erroneamente una variabile numerica locale con lo stesso nome come funzione globale.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Below is an example, where a local numeric variable sum is picked up by globalsOf(), despite the expression uses a function sum().
sum <- 42
expr <- quote( sum(1:10) )
names <- globals::findGlobals(expr)
print(names)
#> "{" "sum" ":"
objs <- globals::globalsOf(expr)
str(objs)
#> List of 3
#> $ { :.Primitive("{")
#> $ sum: num 42
#> $ : :.Primitive(":")
#> - attr(*, "where")=List of 3
#> ..$ { :<environment: base>
#> ..$ sum:<environment: R_GlobalEnv>
#> ..$ : :<environment: base>
#> - attr(*, "class")= chr [1:2] "Globals" "list"
Ideally, globalsOf() would pick up base::sum() instead. For that to happen, we need to refine globals::findGlobals() to record whether symbol sum refers to a function or not. That could be achieved by findGlobals() inspect the language object that sum is part of. For instance, from:
expr <- quote( sum(1:10) )
str(list(first = expr[[1]], class = class(expr), typeof = typeof(expr), length = length(expr)))
#> List of 4
#> $ first : symbol sum
#> $ class : chr "call"
#> $ typeof: chr "language"
#> $ length: int 2
expr <- quote( sum )
str(list(class = class(expr), typeof = typeof(expr), length = length(expr)))
#> List of 3
#> $ class : chr "name"
#> $ typeof: chr "symbol"
#> $ length: int 1
## But it's not that easy
expr <- quote( sum + 2 )
str(list(first = expr[[1]], class = class(expr), typeof = typeof(expr), length = length(expr)))
#> List of 4
$ first : symbol +
#> $ class : chr "call"
#> $ typeof: chr "language"
#> $ length: int 3
expr <- quote( -sum )
str(list(first = expr[[1]], class = class(expr), typeof = typeof(expr), length = length(expr)))
#> List of 4
$ first : symbol -
#> $ class : chr "call"
#> $ typeof: chr "language"
#> $ length: int 2
we see that we can infer when symbol sum is the name of a function call or not.
One could have findGlobals(expr, annotate = TRUE) return this information as well, e.g. as attributes. But, is that shoehorning the original design of globals to much, which is basically an enhancement of codetools? It would be worth investigating if there are better AST tools for what's trying to be achieved. OTH, the above improvement might be good enough for 99% of the use cases.
- Lingua principale
- R
- Stelle
- 29
- Fork
- 3
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di futureverse/globals
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
futureverse/globals#98 ·
-
bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 42/100
futureverse/globals#91 · 1 commento · 1 reazione ·
-
bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
futureverse/globals#87 · 1 commento ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
futureverse/globals#75 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
futureverse/globals#65 · 2 commenti ·
Tutte le issue di futureverse/globals
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
nf-core/provenancereport#75 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
futureverse/future#852 · 1 commento ·
-
Typo in Exercise 5.22?Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100