pharmaverse / pharmaverse/rtables

slightly relax label validity check

Open
#871 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

sme
Dominant language
R
Stars
260
Forks
53
PR merge metrics
No merged PRs in 30d

Description

Currently any use of "{" or "}" in a label is disallowed here:

https://github.com/insightsengineering/rtables/blob/bdafa9d155ef71c7bc829d17c5ba78ae5a7c8308/R/00tabletrees.R#L23

This is due to formatters historically/currently being somewhat overly aggresive in guessing where referential footnotes are

I'd like to relax this to checking for the pattern " [{][^}]+[}]" (including the space)

This is due to formatting instructions being embedded in strings in the form, e.g., "~{super a}" for superscripted a in study metadata tracking tools. I didn't choose this, but I also can't change it, and with the leading ~ it is distinguishable from a referential footnote.

This will require a change to how refdefs are inferred in formatters to be safe, in particular, here:

https://github.com/insightsengineering/formatters/blob/63530282db089234559b865ef031814907ec6075/R/matrix_form.R#L381

Splitting that one gsub into two regexes, one grep to detect them which has the space and then the gsub to extract them, should be sufficient, e.g.,

refs <- matrix("", nrow = nrow(strs), ncol = ncol(strs))
haveref <- grepl(" [{][^}]*[}]", strs) ## with space
refs[haveref] <-  gsub("^[^{]*([{]([^}]+)[}]){0,1}$", "\\2", strs[haveref]) ## without space, but only ones we know had one

Contributor guide

Open the contributing guide

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.

Research direction

Start at R/00tabletrees.R line 23 in rtables to review the label validity check, then read formatters/R/matrix_form.R line 381 where refdefs are inferred. Verify that labels containing braces are accepted only when matching the stated space-prefixed pattern, while referential footnotes continue to be detected and extracted correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.