OuhscBbmc / REDCapR

R utilities for interacting with REDCap
https://ouhscbbmc.github.io/REDCapR
Other
112 stars 45 forks source link

Trailing newline in Checkbox option causes choice to omitted #501

Closed BlairCooper closed 11 months ago

BlairCooper commented 11 months ago

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):

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.

wibeasley commented 11 months ago

@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 commented 11 months ago

@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 commented 11 months ago

@wibeasley Re: CSV, see comments on #500

wibeasley commented 11 months ago

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