-
Notifications
You must be signed in to change notification settings - Fork 48
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
🐛 Fix coltypes for projects with dags #472
🐛 Fix coltypes for projects with dags #472
Conversation
update urls
for older version of REDCap
lintr & cleanup
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.
@pwildenhain, this looks great. I have only one comment involving code.
In addition, can you please add an entry in https://github.com/OuhscBbmc/REDCapR/blob/main/NEWS.md#minor-enhancements? Maybe along the lines of "redcap_meta_coltypes()
correctly determines data type for autonumber fields. It suggests a character if the project has DAGs, and an integer if not. (@pwildenhain , #472)"
@pwildenhain, I see you just added me as a reviewer. I think you've added everything except for the line that explicitly specifies "character" for autonumbering w/ dags. Am I overlooking it? As the waterfall is written now, it shouldn't affect the recommended type. But two benefits are
|
Oh I see what you're saying. I took a different approach. I decided to say if there was autonumbering and there were not dags, then the field could still be considered an integer. Otherwise, I saw that it would fall to the catchall "character" case at the end of the waterfall: REDCapR/R/redcap-metadata-coltypes.R Line 447 in 7799eab
But it sounds like you're saying it would be nice to add a case to the waterfall for the situation where you have autonumbering and dags, so we could explain to the user why we assigned a character? Just want to make sure I understand before I go add that second case |
yeah, that's a good way to say it. Ideally the col_types entry has an informative comment/explanation. If it helps to visualize, this is an example current output: # A simple project
token <- "9A81268476645C4E5F03428B8AC3AA7B" # 153
col_types <- redcap_metadata_coltypes(uri, token)
#> # col_types <- readr::cols_only( # Use `readr::cols_only()` to restrict the retrieval to only these columns
#> col_types <- readr::cols( # Use `readr::cols()` to include unspecified columns
#> # [field] [readr col_type] [explanation for col_type]
#> record_id = readr::col_integer() , # record_autonumbering is enabled for the project
#> name_first = readr::col_character() , # field_type is text and validation isn't set
#> name_last = readr::col_character() , # field_type is text and validation isn't set
#> address = readr::col_character() , # field_type is note
#> telephone = readr::col_character() , # validation is 'phone'
#> email = readr::col_character() , # validation is 'email'
#> dob = readr::col_date() , # validation is 'date_ymd'
#> age = readr::col_character() , # field_type is text and validation isn't set
#> sex = readr::col_character() , # field_type is radio
... |
Hold off on merging this for now -- I'm just now realizing that this function will fail if the user is currently assigned to a DAG -- since you can't access the "Export DAGs" API endpoint when you assigned to a DAG. I think we can maneuver around this though. |
Ok @wibeasley I've added some code to account for that edge case, and I've tested it with one of my projects to make sure it works. PR is ready for review again. |
Pinging @wibeasley again to review -- not sure why the tests failed |
I meant to check it out more deeply. I thought it was something fluky and that's why I hit some limit of four rerunning. I've changed the base to dev and I'll try some things now. |
@@ -380,7 +380,8 @@ redcap_metadata_internal <- function( | |||
dplyr::mutate( | |||
response = | |||
dplyr::case_when( | |||
autonumber & !dags ~ paste0("col_integer()" , "~~record_autonumbering is enabled for a project without DAGs"), | |||
dags ~ paste0("col_character()" , "~~DAGs are enabled for the project"), |
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.
Sorry for so much blabbing over one line. Can you check my logic? Wouldn't it be better to change dags
to autonumber & dags
? Otherwise, I think it would execute for all variables in any project with dags.
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.
No worries haha. dags
will only evaluate to TRUE
when the field is the .record_id
field AND the project has DAGs (similar to how autonumber
already works
Fixes #467