Skip to content

Keep non-missing elements when pluralize() collapses a vector with NA - #852

Open
Don-Yin wants to merge 1 commit into
r-lib:mainfrom
Don-Yin:fix-pluralize-na
Open

Don-Yin wants to merge 1 commit into
r-lib:mainfrom
Don-Yin:fix-pluralize-na

Conversation

@Don-Yin

@Don-Yin Don-Yin commented Oct 26, 2026

Copy link
Copy Markdown

Fixes #717.

pluralize("{c('file1', 'file2', NA)} file{?s}") gave "NA files": glue turns the whole substitution into NA as soon as one element is missing, so the other names were lost before collapsing. I now replace the missing elements with .na inside the transformer, before inline_collapse(), and keep the original quantity for the plural. .na already reached glue through ..., so I made it an explicit argument to use it in both places. The default, a custom .na and .na = NULL behave as before for everything else.

repro on main and with this change

I added a test in test-pluralization.R for the example from the issue plus the .na variants. The pluralization, collapsing, inline and glue tests pass locally.

Fixes r-lib#717

Signed-off-by: Don Yin <Don_Yin@outlook.com>

This branch has not been deployed

No deployments
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.

NAs in pluralize vector cause values to not display correctly

1 participant