The same functionality should help deal with instruments that are
potentially given repeatedly. Common examples include asking
participants to fill out a form describing medical conditions for all
their siblings or asking them to fill out a form for each side effect
they experience while using a drug. In these cases, each participant may
have zero or many records. Again, creating a table with all the records
for these “repeated” instruments would be good.
# Do not type your API token directly into your code ::import_instruments( tidyREDCapurl = "https://redcap.miami.edu/api/", token = "1A2B3CXXYYZZOOMMGOSHNOOOOX1Y2Z3" # This is BAD! ) # A better way to do this is to read the API key from the .Renviron file. # For instructions on saving your API key, see link below. ::import_instruments( tidyREDCapurl = "https://redcap.miami.edu/api/", token = Sys.getenv("nacho_anxiety_key") # This is BETTER! )
See the Importing from REDCap vignette for details/information for saving your API key in the .Renviron file.
import_instruments() function can be given a URL and
token for a REDCap project, like the one created above and it will
return one table for each instrument in a project. By default, the
function will drop all empty records. For example, the above API call is
pulling data from a REDCap project that has four instruments:
Enrollment, the Nacho Craving Index (NCI), the Generalized Anxiety
Disorder Assessment (GAD7), and the Hamilton Anxiety Scale (HAM-A).
After running the above code we get four tables from the REDCap project.
Notice that each repeat of the HAM-A is its own record.
If a person has only done the baseline assessment they will only have one record.