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

Unexpected Behavior: redcap_metadata_coltypes assumes that "record_id" field is an integer #467

Closed
pwildenhain opened this issue Feb 6, 2023 · 2 comments · Fixed by #472
Assignees

Comments

@pwildenhain
Copy link
Contributor

pwildenhain commented Feb 6, 2023

!! Note about security !! If your question/issue involves sensitive information, please do not post it in this public location. You might assist someone in compromising your institution's server or network. The REDCap Community is the appropriate forum. Please ask your institution's REDCap administrator to post a question on this site, with the tags api and redcapr.

Describe the behavior: Please provide a clear and concise description of the scenario and the behavior. Be careful not to include tokens, PHI (protected health information), or other information that should not be public!

First off, I ❤️ the redcap_metadata_coltypes function, such a hidden gem of this package. It's really saving my bacon in this ETL I'm working on across several very large/old/complex REDCap projects.

In working with it, I discovered that it just assumes that, if autonnumbering is enabled, the record_id field (or first field of the project) is going to be an integer, which doesn't work when DAGs are involved (since records look more like this: 5373-100 than this 100)

Expected behavior: A clear and concise description of what you expected to happen.

It would be great if this function were "DAG" aware, and looked for that first before looking at autonumbering, in order to determine the data type of the record_id field.

Desktop (please complete the following information):

  • OS: Mac
  • REDCap version: 12.5.15
  • REDCapR Version: GitHub development version

Additional context: Add any other information about the specific problem, such as a data dictionary or screenshot.

Here's is the part of the code that is causing the issue for me:

.autonumber <- d_proj$record_autonumbering_enabled[1]

dplyr::mutate(
response =
dplyr::case_when(
autonumber ~ paste0("col_integer()" , "~~record_autonumbering is enabled for the project"),

I don't think the change would be that difficult 🤞🏻 and I'm happy to contribute if you're aligned with my approach

@wibeasley wibeasley self-assigned this Feb 6, 2023
@pwildenhain
Copy link
Contributor Author

Also, what the reasoning behind calc fields categorized as character?

field_type == "calc" ~ paste0("col_character()" , "~~field_type is calc"),

I thought REDCap calculated fields could only output numbers?

@wibeasley
Copy link
Member

It would be great if this function were "DAG" aware, and looked for that first before looking at autonumbering, in order to determine the data type of the record_id field.

Yes, I completely agree. I'm sure that was an oversight on my part --I didn't consider DAGs.

I don't think the change would be that difficult 🤞🏻 and I'm happy to contribute if you're aligned with my approach

Great, I'd love that. Please tell me if there's anything you'd like to discuss.

What the reasoning behind calc fields categorized as character? ... I thought REDCap calculated fields could only output numbers?

I think that changed in a REDCap release the past year or two? Or I was expecting it to change in a future REDCap version, and I wanted to accommodate it now so code (that expected integers) wouldn't break. I don't really remember. When in doubt, I was trying to be more permissive and use the more flexible data type.

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