[Bug]: `within` doesn't replace the lefthand side of an expression.

Aperta
#275 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

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

Direzione di ricerca

Inizia riproducendo gli esempi segnalati relativi a within, qenv() ed eval_code, quindi esamina l’implementazione di within e i relativi link alla documentazione. Conferma come viene risolto il lato sinistro, verifica se manca la voce di documentazione @aliases within e considera il lavoro completo quando sono coperti il comportamento di mutazione previsto e la ricerca di ?within.

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

Descrizione

bug core
What happened?

I wanted to mutate a variable by using as.factor but I found that using this approach doesn't replace the content but creates a new column:

library("teal.code")
var <- "Species"
q <- within(qenv(),
  {
    library("dplyr")
    iris <- iris
    iris2 <- mutate(iris, a = as.factor(a))
  },
  a = as.name(var)
)
setdiff(colnames(q$iris2), colnames(q$iris))
#> [1] "a"

Created on 2025-10-24 with reprex v2.1.1

One workaround is to use the dplyr's walrus := assignment:

library("teal.code")
var <- "Species"
q <- within(qenv(),
  {
    library("dplyr")
    iris <- iris
    iris2 <- mutate(iris, a := as.factor(a))
  },
  a = as.name(var)
)
setdiff(colnames(q$iris2), colnames(q$iris))
#> character(0)

Created on 2025-10-24 with reprex v2.1.1

but this might confuse readers of the code if this end up on the Show R code on teal.
If not a bug perhaps mentioning this on the documentation would be helpful to users.

Also, I realized that within doesn't have the @aliases within so users searching with ?within will not find it (but it is linked from eval_code and qenv).

sessionInfo()

Relevant log output

Code of Conduct
  • I agree to follow this project's Code of Conduct.
Contribution Guidelines
  • I agree to follow this project's Contribution Guidelines.
Security Policy
  • I agree to follow this project's Security Policy.
Lingua principale
R
Stelle
12
Fork
12
Merge medio
4g 22h
PR unite (30g)
3

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pharmaverse/teal.code

Tutte le issue di pharmaverse/teal.code

Issue simili

Altre issue su R

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.