Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slightly relax label validity check #871

Open
gmbecker opened this issue May 21, 2024 · 1 comment
Open

slightly relax label validity check #871

gmbecker opened this issue May 21, 2024 · 1 comment
Labels

Comments

@gmbecker
Copy link
Collaborator

gmbecker commented May 21, 2024

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

if (grepl("([{}])", lbl)) {

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
@Melkiades
Copy link
Contributor

Melkiades commented May 22, 2024

Good point! Checked, and the expected error message if there are {} in labels is the following:

Error in check_ok_label(label) : 
  Labels cannot contain { or } due to their use for indicating referential footnotes

@shajoezhu shajoezhu added the sme label Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants