Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

format_ae_listing(): AE duration set to NA (not "Unknown") for outcomes outside two hardcoded values

Open Beginner friendly
#159 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
r
Domain
data

Research direction

The bug is in R/ae_listing.R around lines 394-402 in the format_ae_listing() function. First, read the function to understand how ADURN and AEOUT are used. Then, create a small test to reproduce the issue with the provided examples. The fix is to replace the charmatch() calls with an exact membership test using %in%. After making the change, run any existing tests for this function to ensure the fix works and doesn't break other behavior.

Written by the indexing model from the issue text.

Description

bug

When ADURN is missing, format_ae_listing() derives the Duration value from AEOUT (R/ae_listing.R, around lines 394-402):

na_dur <- is.na(res[["ADURN"]])
if (any(na_dur)) {
  aeout_na <- toupper(res[["AEOUT"]][na_dur])
  res[["Duration"]][na_dur] <- ifelse(
    charmatch(aeout_na, "RECOVERING/RESOLVING") > 0 |
      charmatch(aeout_na, "NOT RECOVERED/NOT RESOLVED") > 0,
    "Continuing", "Unknown"
  )
}

Two problems with charmatch() here:

  1. NA leaks into the result. charmatch(x, table) returns NA when x matches nothing in table. For any outcome that is neither RECOVERING/RESOLVING nor NOT RECOVERED/NOT RESOLVED (e.g. FATAL, RECOVERED/RESOLVED), both charmatch() calls return NA, so the ifelse() condition is NA | NA = NA and ifelse(NA, ...) yields NA. The intended fallback "Unknown" is never reached for those rows.

  2. Silent prefix matching. charmatch() does partial (prefix) matching, so charmatch("R", "RECOVERING/RESOLVING") returns 1. An exact comparison was almost certainly intended.

Reproducer:

f <- function(aeout) ifelse(
  charmatch(aeout, "RECOVERING/RESOLVING") > 0 |
    charmatch(aeout, "NOT RECOVERED/NOT RESOLVED") > 0,
  "Continuing", "Unknown")
f("FATAL")               # NA   (expected "Unknown")
f("RECOVERED/RESOLVED")  # NA   (expected "Unknown")

Suggested fix: use an exact set-membership test instead of charmatch():

res[["Duration"]][na_dur] <- ifelse(
  aeout_na %in% c("RECOVERING/RESOLVING", "NOT RECOVERED/NOT RESOLVED"),
  "Continuing", "Unknown"
)

This affects normal, valid data whenever a subject has a missing AE duration and an outcome outside the two listed categories.

Dominant language
R
Stars
22
Forks
6
Avg merge
1d 13h
Merged PRs (30d)
10

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Merck/forestly

All issues in Merck/forestly

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.