Closed larmarange closed 8 months ago
Exploring the code of your package, it seems that most of the work is already done in the internal function multi_choice_to_labels()
. It would therefore be releatively easy to have an option in this function to convert into an haven_labelled
vector instead of a factor.
Thanks for the feature request! This sounds generally useful so we plan on exploring this week and seeing what we can add. We'll be in touch soon!
Thank you.
See if #180 addresses your request. We're definitely interested in your feedback!
This edge case may be of general interest to you too: https://github.com/CHOP-CGTInformatics/REDCapTidieR/pull/180#discussion_r1526626425
I just tested. It worked perfectly. Thanks a lot.
Feature Request Description
For some projects, our data workflow requires to import data from REDCap, make diverse transformations within R and then re-export data to several formats including Stata and SPSS using
haven
package.For categorical variables, we need to keep the original codes used to collect data in REDCap while providing value labels. In
haven
, such data format is handled with thehaven_labelled
class, and several packages exist to deal with it, in particular thelabelled
package: https://larmarange.github.io/labelled/ (to be noted, this package is already suggested by REDCapTidieR).For this purpose, it would be great to be able to import datasets from REDCap directly with the
haven_labelled
format, allowing to store both codes and value labels in the dataset.Proposed Solution
For that, it would be a great addition to have an option
raw_or_label = "haven_labelled"
inread_redcap()
or alternatively a functionmake_haven_labelled()
that could be applied on a super-tibble.Technically:
"raw"
with the current implementation ofread_redcap()
select_choices_or_calculations
inredcap_metadata
will have to be parsed to identify and generate a list of value labelslabelled::set_value_labels()
(through.labels
argument)In fact, the real piece of work is the point 2.
Describe alternatives you've considered
We are considering developing our own internal function. However, we have the feeling that such functionality could be useful for others and that it would be relevant to be integrated in an existing package.
Additional Context
Please let us know if you think that such functionality would be relevant for
REDCapTidieR
. If yes, we would be happy to contribute and/or propose a PR.Checklist