diff --git a/R/getSurvey.R b/R/getSurvey.R index 640e3e9..ac7b569 100644 --- a/R/getSurvey.R +++ b/R/getSurvey.R @@ -104,8 +104,8 @@ getSurvey <- function(surveyID, if(!force_request) { if(paste0(surveyID, ".rds") %in% list.files(tempdir())) { data <- readRDS(paste0(tempdir(), "/", surveyID, ".rds")) - if(verbose) message(paste0("Found an earlier download for survey with id ", surveyID, - ". Loading this file. Set 'force_request' to TRUE if you want to override this.")) + if(verbose) message(paste0("Found an earlier download for survey with id ", surveyID, # nolint + ". Loading this file. Set 'force_request' to TRUE if you want to override this.")) # nolint return(data) } } @@ -143,7 +143,8 @@ getSurvey <- function(surveyID, if(convertVariables) { data <- inferDataTypes(data, surveyID) } - # Save survey as RDS file in temp folder so that it can be easily retrieved this session. + # Save survey as RDS file in temp folder so that it can be easily + # retrieved this session. saveRDS(data, paste0(tempdir(), "/", surveyID, ".rds")) # Remove tmpfiles if(!is.null(save_dir)) { diff --git a/R/getSurveyQuestions.R b/R/getSurveyQuestions.R index ce9dff7..202c347 100644 --- a/R/getSurveyQuestions.R +++ b/R/getSurveyQuestions.R @@ -54,7 +54,9 @@ getSurveyQuestions <- function(surveyID) { quest <- data.frame(qid = names(qi), qnames = vapply(qi, function(x) x$questionName, ""), question = vapply(qi,function(x) x$questionText, ""), - force_resp = vapply(qi, function(x) x$validation$doesForceResponse, TRUE), + force_resp = vapply(qi, + function(x) x$validation$doesForceResponse, # nolint + TRUE), stringsAsFactors = FALSE) # Row names diff --git a/R/metadata.R b/R/metadata.R index c215983..675cc96 100644 --- a/R/metadata.R +++ b/R/metadata.R @@ -49,8 +49,8 @@ metadata <- function(surveyID, allowed <- c("metadata","questions","responsecounts", "blocks","flow","embedded_data","comments") check <- union(allowed, names(get)) - assertthat::assert_that(length(check) <= length(allowed), - msg="One or more options you passed to 'get' are not valid. Please check your input and try again.") + assertthat::assert_that(length(check) <= length(allowed), # nolint + msg="One or more options you passed to 'get' are not valid. Please check your input and try again.") # nolint # Change standard options if any standard_list <- list("metadata"=TRUE, "questions"=TRUE, @@ -97,8 +97,12 @@ metadata <- function(surveyID, "isActive" = resp_filt$isActive, "creationDate" = resp_filt$creationDate, "lastModifiedDate"=resp_filt$lastModifiedDate, - "expiration_startdate"=ifelse(is.null(resp_filt$expiration$startDate),NA,resp_filt$expiration$startDate), - "expiration_endDate"=ifelse(is.null(resp_filt$expiration$endDate),NA,resp_filt$expiration$endDate) + "expiration_startdate"=ifelse(is.null(resp_filt$expiration$startDate), + NA, + resp_filt$expiration$startDate), + "expiration_endDate"=ifelse(is.null(resp_filt$expiration$endDate), + NA, + resp_filt$expiration$endDate) ) # Response counts responsecounts <- data.frame( @@ -114,7 +118,7 @@ metadata <- function(surveyID, if(all(q_select %in% qnames)) { questions <- resp_filt$questions[which(qnames %in% q_select)] } else { - warning(paste0("One or more questions you queried are not present in your survey. Returning all questions instead.")) + warning(paste0("One or more questions you queried are not present in your survey. Returning all questions instead.")) # nolint questions <- resp_filt$questions } } else { @@ -129,7 +133,8 @@ metadata <- function(surveyID, "embedded_data"=resp_filt$embeddedData, "comments"=resp_filt$comments) # Make subset - met_ss <- met[names(standard_list[vapply(standard_list,function(x) x==TRUE, TRUE)])] + met_ss <- met[names(standard_list[vapply(standard_list, + function(x) x==TRUE, TRUE)])] # nolint # Return return(met_ss) } diff --git a/R/qualtRicsConfigFile.R b/R/qualtRicsConfigFile.R index 29c6d1e..4be3c4c 100644 --- a/R/qualtRicsConfigFile.R +++ b/R/qualtRicsConfigFile.R @@ -38,7 +38,7 @@ qualtRicsConfigFile <- function(api_token = NULL, root_url=NULL, verbose=TRUE, useLocalTime=FALSE, dateWarning=TRUE) { msg <- paste0( - "Copy-paste the lines between the dashes into a new plain text file, replace the values for the api_token and root_url if they are not yet filled out. and save it in your working directory as '.qualtRics.yml'. Execute '?qualtRics::qualtRicsConfigFile' to view an explanation of the additional arguments. Visit https://github.com/JasperHG90/qualtRics/blob/master/README.md#using-a-configuration-file for more information.", "\n\n", + "Copy-paste the lines between the dashes into a new plain text file, replace the values for the api_token and root_url if they are not yet filled out. and save it in your working directory as '.qualtRics.yml'. Execute '?qualtRics::qualtRicsConfigFile' to view an explanation of the additional arguments. Visit https://github.com/JasperHG90/qualtRics/blob/master/README.md#using-a-configuration-file for more information.", "\n\n",# nolint "--------------","\n", 'api_token: ', ifelse(is.null(api_token), '', paste0(api_token)), "\n", diff --git a/R/readSurvey.R b/R/readSurvey.R index efee17b..6858c79 100644 --- a/R/readSurvey.R +++ b/R/readSurvey.R @@ -53,12 +53,13 @@ readSurvey <- function(file_name, skip = skipNr)) # Need contingency when 0 rows assertthat::assert_that(nrow(rawdata) > 0, - msg="The survey you are trying to import has no responses.") + msg="The survey you are trying to import has no responses.") # nolint # Load headers header <- suppressMessages(readr::read_csv(file = file_name, col_names = TRUE, n_max = 1)) - # make them data.frame's, else the factor conversion in `inferDataTypes` crashes + # make them data.frame's, else the factor conversion + # in `inferDataTypes` crashes #rawdata <- as.data.frame(rawdata) #header <- as.data.frame(header) # Add names @@ -77,8 +78,8 @@ readSurvey <- function(file_name, # ---------------------------------------------------- if(stripHTML) { # weird regex to strip HTML tags, leaving only content - # https://www.r-bloggers.com/htmltotext-extracting-text-from-html-via-xpath/ - pattern <- "\\s]+))?)+\\s*|\\s*)/?>" + # https://www.r-bloggers.com/htmltotext-extracting-text-from-html-via-xpath/ # nolint + pattern <- "\\s]+))?)+\\s*|\\s*)/?>" # nolint secondrow <- gsub(pattern, "\\4", secondrow) } # Scale Question with subquestion: diff --git a/R/registerOptions.R b/R/registerOptions.R index af292cb..c2c8f63 100644 --- a/R/registerOptions.R +++ b/R/registerOptions.R @@ -69,14 +69,20 @@ registerOptions <- function(verbose=TRUE, # Store root_url/api_token. Else give NA as value root_url <- ifelse("root_url" %in% names(args), args$root_url, NA) api_token <- ifelse("api_token" %in% names(args), args$api_token, NA) - # If environment variables are already set and user just wants to change verbose argument - if(Sys.getenv("QUALTRICS_ROOT_URL") != "" & Sys.getenv("QUALTRICS_API_KEY") != "") { + # If environment variables are already set and user just wants to + # change verbose argument + if(Sys.getenv("QUALTRICS_ROOT_URL") != "" & Sys.getenv("QUALTRICS_API_KEY") != "") { # nolint # Check - assertthat::assert_that(assertthat::is.flag(verbose), msg=paste0("'verbose' must be either TRUE or FALSE.")) - assertthat::assert_that(assertthat::is.flag(convertVariables), msg=paste0("'convertvariables' must be either TRUE or FALSE.")) - assertthat::assert_that(assertthat::is.flag(useLabels), msg=paste0("'uselabels' must be either TRUE or FALSE.")) - assertthat::assert_that(assertthat::is.flag(useLabels), msg=paste0("'uselabels' must be either TRUE or FALSE.")) - assertthat::assert_that(assertthat::is.flag(dateWarning), msg=paste0("'dateWarning' must be either TRUE or FALSE.")) + assertthat::assert_that(assertthat::is.flag(verbose), + msg=paste0("'verbose' must be either TRUE or FALSE.")) # nolint + assertthat::assert_that(assertthat::is.flag(convertVariables), + msg=paste0("'convertvariables' must be either TRUE or FALSE.")) # nolint + assertthat::assert_that(assertthat::is.flag(useLabels), + msg=paste0("'uselabels' must be either TRUE or FALSE.")) # nolint + assertthat::assert_that(assertthat::is.flag(useLabels), + msg=paste0("'uselabels' must be either TRUE or FALSE.")) # nolint + assertthat::assert_that(assertthat::is.flag(dateWarning), + msg=paste0("'dateWarning' must be either TRUE or FALSE.")) # nolint # If user just wants to pass options, do: options( "QUALTRICS_VERBOSE" = verbose, @@ -85,7 +91,8 @@ registerOptions <- function(verbose=TRUE, "QUALTRICS_USELOCALTIME" = useLocalTime ) # Set warning - invisible(ifelse(dateWarning == FALSE, Sys.setenv("QUALTRICS_WARNING_DATE_GIVEN"=TRUE), + invisible(ifelse(dateWarning == FALSE, + Sys.setenv("QUALTRICS_WARNING_DATE_GIVEN"=TRUE), TRUE)) # Set root url and api token if not NA if(!is.na(root_url)) Sys.setenv("QUALTRICS_ROOT_URL" = root_url) @@ -93,57 +100,58 @@ registerOptions <- function(verbose=TRUE, # Quietly quit return(invisible(NULL)) } - # If API token and root url are NA, then look for .qualtRics.yml in the current directory + # If API token and root url are NA, then look for .qualtRics.yml + #in the current directory if(is.na(api_token) & is.na(root_url)) { ex <- file.exists(".qualtRics.yml") # Throw error if file does not exist - assertthat::assert_that(ex == TRUE, msg = "No .qualtRics.yml configuration file found in working directory. Either set your api token and root url using the 'registerOptions' function or create a configuration file. Execute 'qualtRicsConfigFile()' to view an example of a configuration file.") + assertthat::assert_that(ex == TRUE, msg = "No .qualtRics.yml configuration file found in working directory. Either set your api token and root url using the 'registerOptions' function or create a configuration file. Execute 'qualtRicsConfigFile()' to view an example of a configuration file.") # nolint # Load file cred <- yaml::yaml.load_file(".qualtRics.yml") # Assert that names are "api_token" and "root_url" - assertthat::assert_that(all(c("api_token", "root_url") %in% names(cred)), msg="Either the 'api_token' or 'root_url' arguments are missing in your .qualtRics.yml configuration file. Execute 'qualtRicsConfigFile()' to view an example of the configuration file. Execute 'file.edit('.qualtRics.yml')' to edit your configuration file.") + assertthat::assert_that(all(c("api_token", "root_url") %in% names(cred)), msg="Either the 'api_token' or 'root_url' arguments are missing in your .qualtRics.yml configuration file. Execute 'qualtRicsConfigFile()' to view an example of the configuration file. Execute 'file.edit('.qualtRics.yml')' to edit your configuration file.") # nolint # If verbose, print message - if(verbose) message(paste0("Found a .qualtRics.yml configuration file in ", getwd(), ". Using these credentials.")) + if(verbose) message(paste0("Found a .qualtRics.yml configuration file in ", getwd(), ". Using these credentials.")) # nolint # Set vars api_token <- cred$api_token root_url <- cred$root_url # Set optional vars if("verbose" %in% names(cred)) { verbose <- cred$verbose - assertthat::assert_that(assertthat::is.flag(verbose), msg=paste0("'verbose' must be either TRUE or FALSE but is ", as.character(verbose), " in your config file.")) + assertthat::assert_that(assertthat::is.flag(verbose), msg=paste0("'verbose' must be either TRUE or FALSE but is ", as.character(verbose), " in your config file.")) # nolint } # If 'convertStandardColumns' is found in credentials then emit a warning - if('convertstandardcolumns' %in% names(cred) & !'convertvariables' %in% names(cred)) { - message("'convertstandardcolumns' has been deprecated and will be ignored. Please replace it by 'convertvariables' in your '.qualtRics.yml' file. Visit for more information.") + if('convertstandardcolumns' %in% names(cred) & !'convertvariables' %in% names(cred)) { # nolint + message("'convertstandardcolumns' has been deprecated and will be ignored. Please replace it by 'convertvariables' in your '.qualtRics.yml' file. Visit for more information.") # nolint convertVariables <- TRUE - } else if(all(c('convertstandardcolumns', 'convertvariables') %in% names(cred))) { - message("'convertstandardcolumns' has been deprecated and will be ignored. Please remove it from your '.qualtRics.yml' file. Visit for more information.") + } else if(all(c('convertstandardcolumns', 'convertvariables') %in% names(cred))) { # nolint + message("'convertstandardcolumns' has been deprecated and will be ignored. Please remove it from your '.qualtRics.yml' file. Visit for more information.") # nolint convertVariables <- cred$convertvariables } else { convertVariables <- cred$convertvariables } # Check assertthat::assert_that(assertthat::is.flag(convertVariables), - msg=paste0("'convertvariables' must be either TRUE or FALSE but is ", + msg=paste0("'convertvariables' must be either TRUE or FALSE but is ", # nolint as.character(convertVariables), " in your config file.")) if("uselabels" %in% names(cred)) { useLabels <- cred$uselabels - assertthat::assert_that(assertthat::is.flag(useLabels), msg=paste0("'uselabels' must be either TRUE or FALSE but is ", as.character(useLabels), " in your config file.")) + assertthat::assert_that(assertthat::is.flag(useLabels), msg=paste0("'uselabels' must be either TRUE or FALSE but is ", as.character(useLabels), " in your config file.")) # nolint } if("uselocaltime" %in% names(cred)) { useLocalTime <- cred$uselocaltime - assertthat::assert_that(assertthat::is.flag(useLocalTime), msg=paste0("'useLocalTime' must be either TRUE or FALSE but is ", as.character(useLocalTime), " in your config file.")) + assertthat::assert_that(assertthat::is.flag(useLocalTime), msg=paste0("'useLocalTime' must be either TRUE or FALSE but is ", as.character(useLocalTime), " in your config file.")) # nolint } if("datewarning" %in% names(cred)) { dateWarning <- cred$datewarning - assertthat::assert_that(assertthat::is.flag(dateWarning), msg=paste0("'dateWarning' must be either TRUE or FALSE but is ", as.character(dateWarning), " in your config file.")) + assertthat::assert_that(assertthat::is.flag(dateWarning), msg=paste0("'dateWarning' must be either TRUE or FALSE but is ", as.character(dateWarning), " in your config file.")) # nolint } } # Check arguments # If either is still NA AND environment is empty, throw error - assertthat::assert_that(!is.na(root_url) | Sys.getenv("QUALTRICS_ROOT_URL") != "", msg="'root_url' parameter must either be specified in the .qualtRics.yml configuration file or passed to the 'registerOptions' function. To view an example of a configuration file, execute 'qualtRicsConfigFile()'.") - assertthat::assert_that(!is.na(api_token) | Sys.getenv("QUALTRICS_API_KEY") != "", msg="'api_token' parameter must either be specified in the .qualtRics.yml configuration file or passed to the 'registerOptions' function. To view an example of a configuration file, execute 'qualtRicsConfigFile()'.") + assertthat::assert_that(!is.na(root_url) | Sys.getenv("QUALTRICS_ROOT_URL") != "", msg="'root_url' parameter must either be specified in the .qualtRics.yml configuration file or passed to the 'registerOptions' function. To view an example of a configuration file, execute 'qualtRicsConfigFile()'.") # nolint + assertthat::assert_that(!is.na(api_token) | Sys.getenv("QUALTRICS_API_KEY") != "", msg="'api_token' parameter must either be specified in the .qualtRics.yml configuration file or passed to the 'registerOptions' function. To view an example of a configuration file, execute 'qualtRicsConfigFile()'.") # nolint # Set environment variables if(!is.na(api_token)) Sys.setenv("QUALTRICS_API_KEY" = api_token) if(!is.na(root_url)) Sys.setenv("QUALTRICS_ROOT_URL" = root_url) @@ -155,6 +163,7 @@ registerOptions <- function(verbose=TRUE, "QUALTRICS_USELOCALTIME" = useLocalTime ) # Set warning - invisible(ifelse(dateWarning == FALSE, Sys.setenv("QUALTRICS_WARNING_DATE_GIVEN"=TRUE), + invisible(ifelse(dateWarning == FALSE, + Sys.setenv("QUALTRICS_WARNING_DATE_GIVEN"=TRUE), TRUE)) } diff --git a/R/utils.R b/R/utils.R index 2b6932a..6c7747d 100644 --- a/R/utils.R +++ b/R/utils.R @@ -63,24 +63,28 @@ qualtRicsResponseCodes <- function(res, raw=FALSE) { ) ) } else if(res$status_code == 401) { - stop("Qualtrics API raised an authentication (401) error - you may not have the required authorization. Please check your API key and root url.") + stop("Qualtrics API raised an authentication (401) error - you may not have the required authorization. Please check your API key and root url.") # nolint } else if(res$status_code == 400) { - stop("Qualtrics API raised a bad request (400) error - Please report this on https://github.com/JasperHG90/qualtRics/issues") + stop("Qualtrics API raised a bad request (400) error - Please report this on https://github.com/JasperHG90/qualtRics/issues") # nolint } else if(res$status_code == 404) { - stop("Qualtrics API complains that the requested resource cannot be found (404 error). Please check if you are using the correct survey ID.") + stop("Qualtrics API complains that the requested resource cannot be found (404 error). Please check if you are using the correct survey ID.") # nolint } else if(res$status_code == 500) { - stop(paste0("Qualtrics API reports an internal server (500) error. Please contact Qualtrics Support (https://www.qualtrics.com/contact/) and provide the instanceId and errorCode below.", "\n", + stop(paste0("Qualtrics API reports an internal server (500) error. Please contact Qualtrics Support (https://www.qualtrics.com/contact/) and provide the instanceId and errorCode below.", "\n", # nolint "\n", - "instanceId:", " ", httr::content(res)$meta$error$instanceId, "\n", - "errorCode: ", httr::content(res)$meta$error$errorCode)) + "instanceId:", " ", + httr::content(res)$meta$error$instanceId, + "\n", + "errorCode: ", + httr::content(res)$meta$error$errorCode)) return(list( "content" = httr::content(res), "OK"= FALSE )) } else if(res$status_code == 503) { - stop(paste0("Qualtrics API reports a temporary internal server (500) error. Please contact Qualtrics Support (https://www.qualtrics.com/contact/) with the instanceId and errorCode below or retry your query.", "\n", + stop(paste0("Qualtrics API reports a temporary internal server (500) error. Please contact Qualtrics Support (https://www.qualtrics.com/contact/) with the instanceId and errorCode below or retry your query.", "\n", # nolint "\n", - "instanceId:", " ", httr::content(res)$meta$error$instanceId, "\n", + "instanceId:", " ", httr::content(res)$meta$error$instanceId, + "\n", "errorCode: ", httr::content(res)$meta$error$errorCode)) return(list( "content" = httr::content(res), @@ -88,7 +92,7 @@ qualtRicsResponseCodes <- function(res, raw=FALSE) { ) ) } else if(res$status_code == 413) { - stop("The request body was too large. This can also happen in cases where a multipart/form-data request is malformed.") + stop("The request body was too large. This can also happen in cases where a multipart/form-data request is malformed.") # nolint } else if(res$status_code == 429) { stop("You have reached the concurrent request limit.") } @@ -153,29 +157,41 @@ checkParams <- function(...) { # Check if params are of the right type if("startDate" %in% names(args)) { - if(!is.null(args$startDate)) assert_startDate_string(args$startDate) + if(!is.null(args$startDate)) { + assert_startDate_string(args$startDate) + } } if("endDate" %in% names(args)) { if(!is.null(args$endDate)) assert_endDate_string(args$endDate) } if("lastResponseId" %in% names(args)) { - if(!is.null(args$lastResponseId)) assert_lastResponseId_string(args$lastResponseId) + if(!is.null(args$lastResponseId)) { + assert_lastResponseId_string(args$lastResponseId) + } } # Check if save_dir exists if("save_dir" %in% names(args)) { - if(!is.null(args$save_dir)) assert_saveDir_exists(args$save_dir) + if(!is.null(args$save_dir)) { + assert_saveDir_exists(args$save_dir) + } } # Check if seenUnansweredRecode is NULL or else a string if("seenUnansweredRecode" %in% names(args)) { - if(!is.null(args$seenUnansweredRecode)) assert_seenUnansweredRecode_string(args$seenUnansweredRecode) + if(!is.null(args$seenUnansweredRecode)) { + assert_seenUnansweredRecode_string(args$seenUnansweredRecode) + } } # Check if limit > 0 if("limit" %in% names(args)) { - if(!is.null(args$limit)) assert_limit_abovezero(args$limit) + if(!is.null(args$limit)) { + assert_limit_abovezero(args$limit) + } } # Check if includedQuestionIds is a string if("includedQuestionIds" %in% names(args)) { - if(!is.null(args$includedQuestionIds)) assert_includedQuestionIds_string(args$includedQuestionIds) + if(!is.null(args$includedQuestionIds)) { + assert_includedQuestionIds_string(args$includedQuestionIds) + } } } @@ -192,7 +208,8 @@ appendRootUrl <- function(root_url, type = c("responseexports", 'surveys')) { type <- match.arg(type) # Create root url root_url <- paste0(root_url, - ifelse(substr(root_url, nchar(root_url), nchar(root_url)) == "/", + ifelse(substr(root_url, nchar(root_url), + nchar(root_url)) == "/", paste0("API/v3/", type,"/"), paste0("/API/v3/", type,"/"))) # Return @@ -370,7 +387,9 @@ downloadQualtricsExport <- function(check_url, verbose = FALSE) { ty <- qualtRicsResponseCodes(f, raw=TRUE) # To zip file tf <- paste0(tempdir(), - ifelse(substr(tempdir(), nchar(tempdir()), nchar(tempdir())) == "/", + ifelse(substr(tempdir(), + nchar(tempdir()), + nchar(tempdir())) == "/", "temp.zip", "/temp.zip")) # Write to temporary file @@ -379,7 +398,9 @@ downloadQualtricsExport <- function(check_url, verbose = FALSE) { u <- tryCatch({ utils::unzip(tf, exdir = tempdir()) }, error = function(e) { - stop(paste0("Error extracting ", "csv", " from zip file. Please re-run your query.")) + stop(paste0("Error extracting ", + "csv", + " from zip file. Please re-run your query.")) }) # Remove zipfile p <- file.remove(tf) @@ -455,9 +476,11 @@ inferDataTypes <- function(data, # Idea: add ORDER = TRUE/FALSE (if user wants factors to be ordered). Add # REVERSE = TRUE/FALSE if user wants the factor levels to be reversed wrapper_mc <- function(data, col_name, survey_meta) { # Get question data from metadata - meta <- survey_meta[vapply(survey_meta, function(x) x$questionName == col_name, TRUE)] + meta <- survey_meta[vapply(survey_meta, + function(x) x$questionName == col_name, TRUE)] # Level names - ln <- vapply(meta[[1]]$choices, function(x) x$choiceText, "character", USE.NAMES = FALSE) + ln <- vapply(meta[[1]]$choices, + function(x) x$choiceText, "character", USE.NAMES = FALSE) # Convert data %>% mutate(!!col_name := readr::parse_factor(data %>% select(!!col_name) %>% pull(), diff --git a/R/zzz.R b/R/zzz.R index 0816f21..15ccb95 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -14,9 +14,13 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see -' -Loads qualtRics credentials automatically when package is loaded and ".qualtRics.yml" file is present in working directory. User needs to have qualtRics API key and root url stored in a configuration file in working directory. For an example of a configuration file, execute "qualtRicsConfigFile()". See: https://github.com/JasperHG90/qualtRics/blob/master/README.md#using-a-configuration-file -' +# Loads qualtRics credentials automatically when package is loaded +# and ".qualtRics.yml" file is present in working directory. User +# needs to have #qualtRics API key and root url stored in a configuration +# file in working directory. For an example of a configuration file, +# execute "qualtRicsCo#nfigFile()". See: +# https://github.com/JasperHG90/qualtRics/blob/master/README.md#using-a-configuration-file # nolint + .onLoad <- function(libname = find.package("qualtRics"), pkgname="qualtRics") { if(file.exists(".qualtRics.yml")) { diff --git a/tests/testthat/test-assert_register_api_key.R b/tests/testthat/test-assert_register_api_key.R index c58205f..5620cc2 100644 --- a/tests/testthat/test-assert_register_api_key.R +++ b/tests/testthat/test-assert_register_api_key.R @@ -1,7 +1,8 @@ test_that("RegisterApiKey returns TRUE", { # This should fail because no key was stored Sys.setenv("QUALTRICS_API_KEY"="") - expect_error(assert_apikey_stored(), "You need to register your qualtrics API key") + expect_error(assert_apikey_stored(), + "You need to register your qualtrics API key") # Store dummy key qualtRics::registerOptions(api_token="1234", root_url="abcd") # Now expect this to be true diff --git a/tests/testthat/test-exist_save_directory.R b/tests/testthat/test-exist_save_directory.R index c528f06..727298f 100644 --- a/tests/testthat/test-exist_save_directory.R +++ b/tests/testthat/test-exist_save_directory.R @@ -2,6 +2,7 @@ test_that("Save directory exists for getSurvey()", { # Store dummy key qualtRics::registerOptions(api_token="1234", root_url="abcd.qualtrics.com") # Call getsurvey - expect_error(qualtRics::getSurvey("1234", save_dir="/users/jasper/desktop/idonotexist"), + expect_error(qualtRics::getSurvey("1234", + save_dir="/users/jasper/desktop/idonotexist"), "does not exist.") }) diff --git a/tests/testthat/test-getSurvey.R b/tests/testthat/test-getSurvey.R index d628bed..139cf48 100644 --- a/tests/testthat/test-getSurvey.R +++ b/tests/testthat/test-getSurvey.R @@ -1,4 +1,4 @@ -context("Get a survey from qualtRics and pull it into R using the getSurvey() function") +context("Get a survey from qualtRics and pull it into R using the getSurvey() function") # nolint # Test - use mock API from httptest package with_mock_api({ diff --git a/tests/testthat/test-getSurveyQuestions_throws_error.R b/tests/testthat/test-getSurveyQuestions_throws_error.R index a2bf07d..69652c4 100644 --- a/tests/testthat/test-getSurveyQuestions_throws_error.R +++ b/tests/testthat/test-getSurveyQuestions_throws_error.R @@ -1,6 +1,7 @@ test_that("getSurveyQuestions() throws an error", { # Store dummy key - qualtRics::registerOptions(api_token="1234", root_url="https://yourdatacenterid.qualtrics.com") + qualtRics::registerOptions(api_token="1234", + root_url="https://yourdatacenterid.qualtrics.com") # This should fail in 'do.call' expect_error(qualtRics::getSurveyQuestions("1234"), "you may not have the required authorization") diff --git a/tests/testthat/test-getSurvey_reads_stored_survey.R b/tests/testthat/test-getSurvey_reads_stored_survey.R index d01df2d..1f8a39b 100644 --- a/tests/testthat/test-getSurvey_reads_stored_survey.R +++ b/tests/testthat/test-getSurvey_reads_stored_survey.R @@ -1,4 +1,4 @@ -test_that("getSurvey() reads a stored survey in temporary directory if exists", { +test_that("getSurvey() reads a stored survey in temporary directory if exists", { # nolint # Register dummy key qualtRics::registerOptions(api_token="1234", root_url="https://yourdatacenterid.qualtrics.com") @@ -10,6 +10,6 @@ test_that("getSurvey() reads a stored survey in temporary directory if exists", saveRDS(data, "surveyID.rds") # Query with all options expect_message(qualtRics::getSurvey("surveyID"), - "Loading this file. Set 'force_request' to TRUE if you want to override this.") + "Loading this file. Set 'force_request' to TRUE if you want to override this.") # nolint }) diff --git a/tests/testthat/test-getSurveys.R b/tests/testthat/test-getSurveys.R index e5b57e4..39de579 100644 --- a/tests/testthat/test-getSurveys.R +++ b/tests/testthat/test-getSurveys.R @@ -2,14 +2,14 @@ context("Get a list of surveys that the user has access to on Qualtrics") # Test - use mock API from httptest package with_mock_api({ - test_that("getSurveys() returns a data frame with columns 'id', 'name', 'ownerId', 'lastModified', 'isActive' columns", { + test_that("getSurveys() returns a data frame with columns 'id', 'name', 'ownerId', 'lastModified', 'isActive' columns", { # nolint testthat::skip_on_cran() registerOptions(root_url="t.qualtrics.com", api_token="1234") # Get survey surveys <- getSurveys() # TESTS expect_that(names(surveys), - is_identical_to(c("id","name","ownerId","lastModified","isActive"))) + is_identical_to(c("id","name","ownerId","lastModified","isActive"))) # nolint expect_equal(nrow(surveys), 1) expect_type(surveys, "list") }) diff --git a/tests/testthat/test-getSurveys_throws_error.R b/tests/testthat/test-getSurveys_throws_error.R index fb7263f..81a3ddb 100644 --- a/tests/testthat/test-getSurveys_throws_error.R +++ b/tests/testthat/test-getSurveys_throws_error.R @@ -1,6 +1,7 @@ test_that("getSurveys() throws an error", { # Store dummy key - qualtRics::registerOptions(api_token="1234", root_url="https://yourdatacenterid.qualtrics.com") + qualtRics::registerOptions(api_token="1234", + root_url="https://yourdatacenterid.qualtrics.com") # This should fail in 'do.call' expect_error(qualtRics::getSurveys(), "you may not have the required authorization") diff --git a/tests/testthat/test-qualtRicsConfFile_message_works.R b/tests/testthat/test-qualtRicsConfFile_message_works.R index 26b5882..93beddd 100644 --- a/tests/testthat/test-qualtRicsConfFile_message_works.R +++ b/tests/testthat/test-qualtRicsConfFile_message_works.R @@ -1,5 +1,5 @@ test_that("qualtRicsConfigFile() cats a message to console", { # Call getsurvey expect_output(qualtRics::qualtRicsConfigFile(), - "Copy-paste the lines between the dashes into a new plain text file, replace the values for the api_token and root_url") + "Copy-paste the lines between the dashes into a new plain text file, replace the values for the api_token and root_url") # nolint }) diff --git a/tests/testthat/test-readSurvey_reads_qualtrics_csv.R b/tests/testthat/test-readSurvey_reads_qualtrics_csv.R index f8ba24c..20b6821 100644 --- a/tests/testthat/test-readSurvey_reads_qualtrics_csv.R +++ b/tests/testthat/test-readSurvey_reads_qualtrics_csv.R @@ -1,4 +1,4 @@ -test_that("readSurvey() reads data in qualtrics standard and legacy format and converts columns", { +test_that("readSurvey() reads data in qualtrics standard and legacy format and converts columns", { # nolint # Test if can read standard format survey <- suppressWarnings(qualtRics::readSurvey("files/sample.csv")) @@ -9,7 +9,7 @@ test_that("readSurvey() reads data in qualtrics standard and legacy format and c expect_true(is.numeric(survey$LocationLatitude)) # Test if can read legacy format - survey_legacy <- suppressWarnings(qualtRics::readSurvey("files/sample_legacy.csv", + survey_legacy <- suppressWarnings(qualtRics::readSurvey("files/sample_legacy.csv", # nolint legacyFormat = TRUE)) # Tests expect_equal(dim(survey_legacy)[1], 1) diff --git a/tests/testthat/test-root_url_fails.R b/tests/testthat/test-root_url_fails.R index a934b74..ef3a19b 100644 --- a/tests/testthat/test-root_url_fails.R +++ b/tests/testthat/test-root_url_fails.R @@ -1,7 +1,7 @@ -test_that("Registering root url that doesn't end with '.qualtrics.com' fails.", { +test_that("Registering root url that doesn't end with '.qualtrics.com' fails.", { # nolint # Store dummy key qualtRics::registerOptions(api_token="1234", root_url="abcd") # This should error on checkParams expect_error(qualtRics::getSurveys(), - "The qualtrics root url must end with '.qualtrics.com'. Your root url looks like this: 'abcd'. Please visit https://api.qualtrics.com/docs/root-url for instructions about the qualtrics root url.") + "The qualtrics root url must end with '.qualtrics.com'. Your root url looks like this: 'abcd'. Please visit https://api.qualtrics.com/docs/root-url for instructions about the qualtrics root url.") # nolint }) diff --git a/tests/testthat/test-seenUnansweredRecode.R b/tests/testthat/test-seenUnansweredRecode.R index 6e68ac7..de1fd2c 100644 --- a/tests/testthat/test-seenUnansweredRecode.R +++ b/tests/testthat/test-seenUnansweredRecode.R @@ -1,6 +1,7 @@ test_that("seenUnansweredRecode is a string", { # Store dummy key - qualtRics::registerOptions(api_token="1234", root_url="https://yourdatacenterid.qualtrics.com") + qualtRics::registerOptions(api_token="1234", + root_url="https://yourdatacenterid.qualtrics.com") # Call getsurvey expect_error(qualtRics::getSurvey("1234", seenUnansweredRecode = 123), "seenUnansweredRecode is not a string")