Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

format_ae_listing(): AEDOSDUR parser errors on repeated Y/M/D designator and is not vectorized

Chiusa
#160 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Una pull request collegata è già stata integrata.

  • #162 di @yihui — integrata

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
65/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
r
Ambito
data

Direzione di ricerca

The bug is in R/ae_listing.R lines 458-501. Start by reading the format_ae_listing() function and the loop that parses AEDOSDUR. Understand how gregexpr works and why a repeated designator causes an error. Look into vectorized regex solutions using sub or regmatches. Check related issues #138 and #148 for context. A fix should replace the loop with a vectorized parser and handle malformed input gracefully. Test with sample data containing repeated 'Y', 'M', or 'D' letters.

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

Descrizione

bug

The Total_Dose_on_Day_of_AE_Onset derivation in format_ae_listing() parses the ISO-8601-like AEDOSDUR string one row at a time (R/ae_listing.R, around lines 458-501), branching on unlist(gregexpr("Y", ...)) > 0 etc.:

for (i in 1:length(res[["AEDOSDUR"]])) {
  if (unlist(gregexpr("Y", res[["ymd"]][i])) > 0) { ... }
  if (unlist(gregexpr("M", res[["ymd"]][i])) > 0) { ... }
  if (unlist(gregexpr("D", res[["ymd"]][i])) > 0) { ... }
}

Bug. gregexpr() returns every match position. If a value contains a designator letter more than once, the result has length > 1, and if (... > 0) raises a hard error on R >= 4.2:

r <- unlist(gregexpr("Y", "1Y2Y3D"))   # c(2, 4)
if (r > 0) "x"
#> Error: the condition has length > 1

Valid ISO 8601 durations use each designator once, so this is latent, but any malformed / dirty AEDOSDUR value triggers it. Also note gregexpr matches literally, so an unexpected letter elsewhere in the string could match.

Secondary (readability / performance). The loop calls gregexpr()/substring() roughly nine times per row for a task a single vectorized regex handles. A capture-group approach (e.g. sub("^(?:([0-9]+)Y)?(?:([0-9]+)M)?(?:([0-9]+)D)?$", ...) or regmatches) removes both the loop and the length>1 hazard, and pluralizes units cleanly.

Related cleanup: #138, #148.

Lingua principale
R
Stelle
23
Fork
6
Merge medio
2g 16h
PR unite (30g)
16

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

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 Merck/forestly

Tutte le issue di Merck/forestly

Issue simili

Altre issue su R

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.