Skip to content

Fix parsepvalue(brackets = TRUE) having no effect - #47

Open
vertesy wants to merge 2 commits into
devfrom
fix-parsepvalue-brackets-noop
Open

Fix parsepvalue(brackets = TRUE) having no effect#47
vertesy wants to merge 2 commits into
devfrom
fix-parsepvalue-brackets-noop

Conversation

@vertesy

@vertesy vertesy commented Aug 28, 2026

Copy link
Copy Markdown
Owner

The bug

parsepvalue() computed the bracket-wrapped string with if (brackets) paste0("(", pv, ")") else pv, but never assigned that result anywhere — it was a bare expression statement, not the function's last expression, so R discarded it. The function's actual return value came only from the final if (!isFALSE(prefix)) ... else pv line, which always operated on the un-bracketed pv.

Why it happened

Classic R gotcha: only a function's last expression is its implicit return value. The bracket-wrapping if/else sat one statement too early to matter.

Impact

Every call to parsepvalue(..., brackets = TRUE) has always silently ignored the brackets flag and returned the same string as brackets = FALSE. E.g. parsepvalue(0.03, brackets = TRUE) returned "p<=0.03" instead of the documented "(p<=0.03)".

Fix

Assign the bracket-wrapping back to pv (if (brackets) pv <- paste0("(", pv, ")")) so it actually participates in the returned value, including when combined with prefix. Also documented the prefix parameter, which R CMD check flagged as missing from the roxygen block (undocumented arguments with a \usage entry are a WARNING).

Version bumped 1.2.1 → 1.2.2 in Development/config.R and DESCRIPTION.

Validation

Manually confirmed parsepvalue() now brackets correctly alone and combined with prefix; ordinary (no-bracket) output is unchanged. R CMD check and the existing testthat suite (7/7 passing) were run on this branch; the undocumented-prefix WARNING is gone. Remaining R CMD check findings (parFlags example error, %!in% Rd-name warning, sandbox locale warning) are pre-existing and out of scope, addressed in other PRs in this batch or environment-inherent.


Generated by Claude Code

claude added 2 commits August 27, 2026 21:22
parsepvalue() computed the bracket-wrapped string with
`if (brackets) paste0("(", pv, ")") else pv`, but never assigned that
result anywhere; it was a bare expression statement, not the function's
last expression, so R discarded it. The function's actual return value
came only from the final `if (!isFALSE(prefix)) ... else pv` line,
which always operated on the un-bracketed `pv`.

Impact: every call to parsepvalue(..., brackets = TRUE) has always
silently ignored the brackets flag and returned the same string as
brackets = FALSE. E.g. parsepvalue(0.03, brackets = TRUE) returned
"p<=0.03" instead of the documented "(p<=0.03)".

Fix: assign the bracket-wrapping back to `pv` (`if (brackets) pv <-
paste0("(", pv, ")")`) so it actually participates in the returned
value, including when combined with `prefix`. Also documented the
`prefix` parameter, which R CMD check flagged as missing from the
roxygen block (undocumented arguments with a \usage entry are a WARNING).

Version bumped 1.2.1 -> 1.2.2 in Development/config.R and DESCRIPTION.

Validation: manually confirmed parsepvalue() now brackets correctly
alone and combined with `prefix`, ordinary (no-bracket) output is
unchanged. R CMD check and the existing testthat suite (7/7 passing)
were run on this branch; the undocumented-prefix WARNING is gone.
Remaining R CMD check findings (parFlags example error, %!in% Rd name
warning, sandbox locale warning) are pre-existing and out of scope,
addressed in other PRs in this batch or environment-inherent.
…ts-noop

# Conflicts:
#	DESCRIPTION
#	Development/config.R
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants