plot.R: non-NA row-count filter collapses to a scalar, giving wrong point nudge spacing
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-visualization
Research direction
The bug is in R/plot.R, lines 211, 500, and 852, within the functions plot_dot(), plot_errorbar(), and table_panel(). Start by reading the current row-count filter logic and the provided reproducer. The fix is to replace the scalar sum with rowSums to filter rows not entirely NA. Test the change by running the reproducer and checking the static RTF plotting path (rtf_static_forestly()).
Written by the indexing model from the issue text.
Description
In plot_dot(), plot_errorbar(), and table_panel() the per-item vertical nudge is computed from a "count of rows that are not fully NA" (R/plot.R, e.g. lines 211, 500, 852):
row_count <- max(nrow(x[!sum(is.na(x[, 1:n_col])) == n_col, ]), 1)
The index expression does not do what it looks like. sum(is.na(x[, 1:n_col])) sums NAs over the entire sub-frame, producing a single scalar; !scalar == n_col is therefore one logical value, which is recycled across all rows. So the filter keeps all rows or zero rows, never a per-row subset.
Reproducer (n_col = 2):
sel <- function(df) { keep <- !sum(is.na(df[,1:2])) == 2; nrow(df[keep,,drop=FALSE]) }
sel(data.frame(x1=c(1,2), x2=c(3,4))) # 2 (no NA -> keep all)
sel(data.frame(x1=c(1,NA), x2=c(3,NA))) # 0 (2 NAs total -> drop all)
Effect: row_count equals the full group size in the normal case, but is forced to 1 whenever a group happens to contain exactly n_col NA values total, which changes nudge_unit(row_count) and misplaces the plotted points vertically. This only affects the static RTF plotting path (rtf_static_forestly()), and the visual effect is subtle, but the logic is incorrect.
Likely intended: count rows that are not entirely NA, per row, e.g.
not_all_na <- rowSums(is.na(x[, 1:n_col])) != n_col
row_count <- max(sum(not_all_na), 1)
The same expression is duplicated in all three functions and should be fixed once (see also the broader duplication across these functions).
- 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Merck/forestly
-
format_ae_listing(): AE duration set to NA (not "Unknown") for outcomes outside two hardcoded values Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 65/100
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
easystats/performance#950 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
briandconnelly/airnow#9 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
OHDSI/CohortConstructor#774 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100