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

Trailing newline in Checkbox option causes choice to omitted #501

Closed
BlairCooper opened this issue Jul 15, 2023 · 4 comments
Closed

Trailing newline in Checkbox option causes choice to omitted #501

BlairCooper opened this issue Jul 15, 2023 · 4 comments

Comments

@BlairCooper
Copy link
Contributor

Describe the behavior: If there is an extra newline after the last option for a checkbox, the regular expression for extracting the checkbox choices will omit the last option.

Assume the options for a REDCap checkbox field are set as follows: (note trailing newline after the last option)

1, Depressive mood disorder
2, Adjustment disorder
3, Personality disorder
4, Anxiety
0, Not Noted

The resulting value in the "select_choices_or_calculations" field will be as follows: (note the extra trailing pipe at the end)

"1, Depressive mood disorder | 2, Adjustment disorder| 3, Personality disorder | 4, Anxiety | 0, Not Noted|" (note the trailing pipe at the end

Calling checkbox_choices() will only return choices 1 through 4, omitting 0.

Expected behavior: All of the checkbox options are returned from checkbox_choices().

Desktop (please complete the following information):

  • OS: Windows 10
  • REDCap version 13.7.5
  • REDCapR Version 1.1.0

Additional context:
Side note: It is actually now not possible to create these scenarios in REDCap 13.7.5. Looks like they've added JavaScript to clean up the options when the field is saved. I was encountering these issues with fields that had been setup with an earlier version of REDCap. So you can't create these scenarios in 13.7.5 but they can still exist in that version.

BlairCooper added a commit to BlairCooper/REDCapR that referenced this issue Jul 15, 2023
fixes OuhscBbmc#501

- Modified pattern_checkboxes regular expression to allow for case where
  there is no space in front of the pipe character in the Lookbehind and
  Lookahead expressions, and allow the space(s) after the comma to be
  optional.

- Created test case to verify correct handling when a checkbox options
  has a trailing newline.

- Created test case to verify correct handling when the space is missing
  after the comma for an option.
@wibeasley
Copy link
Member

wibeasley commented Jul 15, 2023

@BlairCooper, man you're devious. I like it. Did you see #500? I think that approach will be more robust. Will you try that branch?

Conceptually, extra lines shouldn't make a difference. readr will just ignore them. Try this around line 50 of the test file.

  # extra lines
  "| | 1, American Indian/Alaska Native | | | -2, Asian | 3, Native Hawaiian or Other Pacific Islander | 4, Black or African American | 5, White | 66, Unknown / Not Reported | | | " |>
    checkbox_choices() |>
    expect_equal(ds_expected, label = "extra lines:")

@wibeasley
Copy link
Member

@BlairCooper, I just read through your commit more carefully. I like all the detail in the regex explanation. That's a good way to explain it. I was having trouble keeping track of the parts.

@BlairCooper
Copy link
Contributor Author

@wibeasley Re: CSV, see comments on #500

wibeasley added a commit that referenced this issue Jul 15, 2023
@wibeasley
Copy link
Member

As a result of the scenario you raised in this issue, PR #504 addresses extra new lines. Thank you.

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 a pull request may close this issue.

2 participants