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

plot.R: non-NA row-count filter collapses to a scalar, giving wrong point nudge spacing

Open Beginner friendly
#161 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

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

bug

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

  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.