-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add factor levels to redcap_events col #211
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One tiny suggestion but looks good overall!
R/read_redcap.R
Outdated
# Preserve factor levels post-join by referencing level order from linked_arms | ||
repeat_event_types$redcap_event_name <- factor(repeat_event_types$redcap_event_name, | ||
levels = levels(event_info$unique_event_name), | ||
ordered = TRUE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would actually not make this ordered. We don't really know if the events in an arbitrary REDCap have meaningful order and using a plain factor
will still preserve the order if they are meaningful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, for my purposes downstream in record_status_dashboard()
creation I wanted to capture info on the order that events appear in the display. There's no real assumptions (to my knowledge) I can make otherwise when just accepting the supertibble. I believe the order that events come out resembles how they're ordered in the UI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed this will work using Prodigy as an example.
> db$redcap_events[[1]]
# A tibble: 1 × 5
redcap_event event_name redcap_arm arm_name repeat_type
<ord> <fct> <chr> <chr> <chr>
1 infusion_sequence Infusion Sequence 1 Arm 1 nonrepeating
> db$redcap_events[[1]]$event_name
[1] Infusion Sequence
23 Levels: Infusion Sequence Screening & Enrollment Manufacturing LD Chemo Pre-Infusion Infusion 1 Day Follow-Up ... Safety/Meds
> db$redcap_events[[1]]$event_name %>% levels()
[1] "Infusion Sequence" "Screening & Enrollment" "Manufacturing" "LD Chemo" "Pre-Infusion"
[6] "Infusion" "1 Day Follow-Up" "3 Day Follow-Up" "7 Day Follow-Up" "10 Day Follow-Up"
[11] "14 Day Follow-Up" "21 Day Follow-Up" "28 Day Follow-Up" "2 Month Follow-Up" "3 Month Follow-Up"
[16] "4 Month Follow-Up" "5 Month Follow-Up" "6 Month Follow-Up" "9 Month Follow-Up" "12 Month Follow-Up"
[21] "Unscheduled" "End of Study" "Safety/Meds"
Description
This PR seeks to add factor levels and their associated order to the event names and their associated labels when available in the
redcap_events
column of the supertibble. It does not change howredcap_event
appears in the data tibbles of the supertibble, which I think is fine since it should represent the REDCapR output. Users can easily get the level order from theredcap_events
column of the supertibble with this branch's setup and it will serve my use case for REDCapExploreR.Proposed Changes
List changes below in bullet format:
forcats
toDESCRIPTION
to make use offct_inorder()
link_arms()
to establish and assign factor levels and ordersadd_event_mapping()
to uselink_arms()
output and assign factor levels and orderIssue Addressed
Closes #210
PR Checklist
Before submitting this PR, please check and verify below that the submission meets the below criteria:
.RDS
) updated underinst/testdata/create_test_data.R
usethis::use_version()
Code Review
This section to be used by the reviewer and developers during Code Review after PR submission
Code Review Checklist