Search code examples
rparallel-processingqualtrics

R Qualtrics API in Parallel?


I am pulling data from qualtrics using the qualtRics package and I need the data in two forms, one with the breakout_sets option set to TRUE and another version where it is set to FALSE. Is there a way to potentially ping these two versions in parallel to make this process go faster?

library(qualtRics)

qualtrics_api_credentials(api_key = "API KEY",base_url = "url",install = TRUE,overwrite=TRUE)


split_qualtrics <- fetch_survey(surveyID = SURVEYID,
                                unanswer_recode     = -99,
                                unanswer_recode_multi = 0,
                                breakout_sets = TRUE,
                                label = TRUE,
                                force_request = TRUE,
                                verbose = FALSE)


nonsplit_qualitrics <- fetch_survey(surveyID = SURVEYID,
                                       unanswer_recode = -99,
                                       unanswer_recode_multi = 0,
                                       breakout_sets = FALSE,
                                       label = TRUE,
                                       force_request = TRUE,
                                       verbose = FALSE)

Solution

  • You can use the "parallel" assignment operator %<-% of the future package. For example,

    library(qualtRics)
    
    library(future)                  # parallel assignment operator %<-%
    plan(multisession, workers = 2L) # increase for more parallel workers
    
    qualtrics_api_credentials(api_key = "API KEY",base_url = "url",install = TRUE,overwrite=TRUE)
    
    split_qualtrics %<-% fetch_survey(surveyID = SURVEYID,
                                      unanswer_recode     = -99,
                                      unanswer_recode_multi = 0,
                                      breakout_sets = TRUE,
                                      label = TRUE,
                                      force_request = TRUE,
                                      verbose = FALSE)
    
    
    nonsplit_qualitrics %<-% fetch_survey(surveyID = SURVEYID,
                                          unanswer_recode = -99,
                                          unanswer_recode_multi = 0,
                                          breakout_sets = FALSE,
                                          label = TRUE,
                                          force_request = TRUE,
                                          verbose = FALSE)
    

    This will cause the two function calls to run in parallel at the same time. The moment you "touch" split_qualtrics, e.g. try to print its value, your R prompt will block until split_qualtrics is available (nonsplit_qualitrics keeps running in the background). Same rule applies to nonsplit_qualitrics. So, if you do a lot of these, they will all run in the background.