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

Add factor levels to redcap_events col #211

Merged
merged 4 commits into from
Nov 12, 2024
Merged

Conversation

rsh52
Copy link
Collaborator

@rsh52 rsh52 commented Nov 1, 2024

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 how redcap_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 the redcap_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:

  • Add forcats to DESCRIPTION to make use of fct_inorder()
  • Update link_arms() to establish and assign factor levels and orders
  • Update add_event_mapping() to use link_arms() output and assign factor levels and order
  • Update associated tests

Issue Addressed

Closes #210

PR Checklist

Before submitting this PR, please check and verify below that the submission meets the below criteria:

  • New/revised functions have associated tests
  • New/revised functions that update downstream outputs have associated static testing files (.RDS) updated under inst/testdata/create_test_data.R
  • New/revised functions use appropriate naming conventions
  • New/revised functions don't repeat code
  • Code changes are less than 250 lines total
  • Issues linked to the PR using GitHub's list of keywords
  • The appropriate reviewer is assigned to the PR
  • The appropriate developers are assigned to the PR
  • Pre-release package version incremented using usethis::use_version()

Code Review

This section to be used by the reviewer and developers during Code Review after PR submission

Code Review Checklist

  • I checked that new files follow naming conventions and are in the right place
  • I checked that documentation is complete, clear, and without typos
  • I added/edited comments to explain "why" not "how"
  • I checked that all new variable and function names follow naming conventions
  • I checked that new tests have been written for key business logic and/or bugs that this PR fixes
  • I checked that new tests address important edge cases

@rsh52 rsh52 self-assigned this Nov 1, 2024
@rsh52 rsh52 marked this pull request as ready for review November 1, 2024 14:53
@rsh52 rsh52 added the enhancement New feature or request label Nov 1, 2024
@rsh52 rsh52 requested a review from ezraporter November 1, 2024 14:53
Copy link
Collaborator

@ezraporter ezraporter left a 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
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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"    

@rsh52 rsh52 changed the title Add factor levels and order to redcap_events col Add factor levels to redcap_events col Nov 12, 2024
@rsh52 rsh52 requested a review from ezraporter November 12, 2024 14:52
@rsh52 rsh52 merged commit 74f986d into main Nov 12, 2024
4 checks passed
@rsh52 rsh52 deleted the redcap-event-factor-levels branch November 12, 2024 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Make REDCap Event Level Order Accessible for Longitudinal Projects
2 participants