R Qualtrics API是否并行?

zbdgwd5y  于 2023-02-06  发布在  其他
关注(0)|答案(1)|浏览(171)

我正在使用qualtRics包从qualtrics提取数据,需要两种形式的数据,一种形式的breakout_sets选项设置为TRUE,另一种形式的breakout_sets选项设置为FALSE。是否有办法并行ping这两个版本,以加快此过程?

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)
wgxvkvu9

wgxvkvu91#

您可以使用future程序包的“并行”赋值运算符%<-%。例如,

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)

这将导致两个函数调用同时并行运行。当你“触摸”split_qualtrics时,例如试图打印它的值,你的R提示符将被阻塞,直到split_qualtrics可用(nonsplit_qualitrics保持在后台运行)。同样的规则适用于nonsplit_qualitrics。所以,如果你做了很多这样的事情,它们都将在后台运行。

相关问题