Running ‘testthat.R’ [20s/79s]
Running the tests in ‘tests/testthat.R’ failed.
Complete output:
  > library(testthat)
  > library(ctrdata)
  
  Information on this package and how to use it: 
  https://github.com/rfhb/ctrdata/
  
  Please respect the requirements and the copyrights of the
  clinical trial registers when using their information. Call
  ctrOpenSearchPagesInBrowser(copyright = TRUE) and visit
  
  https://www.clinicaltrialsregister.eu/disclaimer.html
  https://clinicaltrials.gov/ct2/about-site/terms-conditions#Use
  
  Testing helper binaries: 
  completed.
  > 
  > test_check("ctrdata")
  
  Downloading: 16 kB     
  Downloading: 16 kB     
  Downloading: 16 kB     
  Downloading: 16 kB     
  Downloading: 16 kB     
  Downloading: 16 kB     
  Downloading: 21 kB     
  Downloading: 21 kB     
  Downloading: 21 kB     
  Downloading: 21 kB     
  Downloading: 21 kB     
  Downloading: 21 kB     
  Downloading: 21 kB     
  Downloading: 21 kB     ── 1. Error: remote mongo access (@testfunctions.R#115)  ───────────────────────
  bad auth Authentication failed.
  1: expect_equivalent(ctrLoadQueryIntoDb(queryterm = "2010-024264-18", register = "CTGOV", 
         uri = uri, collection = coll)$n, 1L) at testthat/testfunctions.R:115
  2: quasi_label(enquo(object), label)
  3: eval_bare(get_expr(quo), get_env(quo))
  4: ctrLoadQueryIntoDb(queryterm = "2010-024264-18", register = "CTGOV", uri = uri, collection = coll)
  5: do.call(ctrLoadQueryIntoDbCtgov, params)
  6: (function (queryterm, register, euctrresults, annotation.text, annotation.mode, details, 
         parallelretrievals, debug, collection, uri, password, verbose, queryupdateterm) 
     {
         queryterm <- sub("(^|&|[&]?\\w+=\\w+&)(\\w+|[NCT0-9-]+)($|&\\w+=\\w+)", "\\1term=\\2\\3", 
             queryterm)
         if (!suppressWarnings(installFindBinary("php --version"))) 
             stop("php not found.", call. = FALSE)
         if (!suppressWarnings(installFindBinary("php -r 'simplexml_load_string(\"\");'"))) 
             stop("php xml not found.", call. = FALSE)
         tempDir <- tempfile(pattern = "ctrDATA")
         dir.create(tempDir)
         queryUSRoot <- "https://clinicaltrials.gov/"
         queryUSType1 <- "ct2/results/download_studies?"
         queryUSType2 <- "ct2/results?"
         if (grepl("^NCT[0-9]{8}$", queryterm)) 
             queryterm <- paste0("term=", queryterm)
         if (!grepl("=", queryterm)) 
             queryterm <- paste0("term=", queryterm)
         message("(1/3) Downloading trials from CTGOV as xml.")
         ctgovdownloadcsvurl <- paste0(queryUSRoot, queryUSType1, "&", queryterm, queryupdateterm)
         if (debug) 
             message("DEBUG: ", ctgovdownloadcsvurl)
         if ("try-error" %in% class(try(httr::headers(httr::HEAD(url = utils::URLencode(queryUSRoot))), 
             silent = TRUE))) 
             stop("Host ", queryUSRoot, " does not respond, cannot continue.", call. = FALSE)
         ctgovdfirstpageurl <- paste0(queryUSRoot, queryUSType2, "&", queryterm, queryupdateterm)
         tmp <- httr::content(httr::GET(url = utils::URLencode(ctgovdfirstpageurl)), as = "text")
         tmp <- gsub("\n|\t|\r", " ", tmp)
         tmp <- gsub("<.*?>", " ", tmp)
         tmp <- gsub("  +", " ", tmp)
         tmp <- sub(".* (.*?) Stud(y|ies) found for.*", "\\1", tmp)
         tmp <- suppressWarnings(as.integer(tmp))
         if (is.na(tmp) || !length(tmp)) {
             message("No trials or number of trials could not be determined: ", tmp)
             return(invisible(list(n = 0L, ids = "")))
         }
         if (as.integer(tmp) > 5000L) {
             message("These are ", tmp, " (more than 5000) trials, this may be unintended. ", 
                 "Please split into separate queries.")
             return(invisible(list(n = 0L, ids = "")))
         }
         message("Retrieved overview, ", tmp, " trial(s) are to be downloaded.")
         f <- paste0(tempDir, "/", "ctgov.zip")
         message("Downloading trials ", appendLF = FALSE)
         tmp <- httr::GET(url = utils::URLencode(ctgovdownloadcsvurl), httr::progress(), 
             httr::write_disk(path = f, overwrite = TRUE))
         if (file.size(f) == 0) 
             stop("No studies downloaded. Please check 'queryterm' or run again with debug = TRUE.", 
                 call. = FALSE)
         utils::unzip(f, exdir = tempDir)
         xml2json <- system.file("exec/xml2json.php", package = "ctrdata", mustWork = TRUE)
         xml2json <- paste0("php -f ", xml2json, " ", tempDir)
         if (.Platform$OS.type == "windows") {
             xml2json <- gsub("\\\\", "/", xml2json)
             xml2json <- gsub("([A-Z]):/", "/cygdrive/\\1/", xml2json)
             xml2json <- paste0("cmd.exe /c c:\\cygwin\\bin\\bash.exe --login -c \"", 
                 xml2json, "\"")
         }
         message("\n(2/3) Converting to JSON ...")
         if (debug) 
             message("DEBUG: ", xml2json)
         imported <- system(xml2json, intern = TRUE)
         mongo <- ctrMongo(collection = collection, uri = uri, password = password, verbose = FALSE)
         if (annotation.text != "") {
             annotations <- mongo$find(query = paste0("{\"_id\": {\"$ne\": \"meta-info\"}}"), 
                 fields = "{\"_id\": 1, \"annotation\": 1}")
         }
         message("(3/3) Importing JSON into mongoDB ...")
         if (debug) 
             message("DEBUG: ", tempDir)
         imported <- dbCTRLoadJSONFiles(dir = tempDir, mongo = mongo)
         cursor <- mongo$iterate(query = "{\"_id\": { \"$regex\": \"^NCT[0-9]{8}\", \"$options\": \"\"} }", 
             fields = "{\"id_info.org_study_id\": 1, \"id_info.secondary_id\": 1}")$batch(size = mongo$count())
         otherids <- sapply(cursor, function(x) paste0(as.vector(unlist(x[2]))))
         cursor <- sapply(cursor, function(x) as.vector(unlist(x[1])))
         for (i in seq_len(length(cursor))) {
             tmp <- sub("\\[\\[", "[", sub("\\]\\]", "]", jsonlite::toJSON(list(otherids = otherids[[i]]))))
             mongo$update(query = paste0("{\"_id\":{\"$eq\":\"", cursor[i], "\"}}"), update = paste0("{ \"$set\" :", 
                 tmp, "}"), upsert = TRUE)
         }
         mongo$index(add = "otherids")
         message("Added index field \"otherids\".")
         mongo$disconnect()
         if ((annotation.text != "") & (length(imported$ids) > 0)) {
             dbCTRAnnotateQueryRecords(recordnumbers = imported$ids, annotations = annotations, 
                 annotation.text = annotation.text, annotation.mode = annotation.mode, 
                 collection = collection, uri = uri, password = password, verbose = verbose)
         }
         message("= Imported or updated ", imported$n, " trial(s).")
         if (!debug) 
             unlink(tempDir, recursive = TRUE)
         return(imported)
     })(queryterm = "2010-024264-18", register = "CTGOV", euctrresults = FALSE, annotation.text = "", 
         annotation.mode = "append", details = TRUE, parallelretrievals = 10, debug = FALSE, 
         collection = "ThisNameSpaceShouldNotExistAnywhereInAMongoDB", uri = "mongodb+srv://7RBnH3BF@cluster0-b9wpw.mongodb.net/dbtemp", 
         password = "", verbose = FALSE, queryupdateterm = "")
  7: ctrMongo(collection = collection, uri = uri, password = password, verbose = FALSE)
  8: mongolite::mongo(collection = collection, url = uri, verbose = verbose)
  9: mongo_collection_command_simple(col, "{\"ping\":1}")
  
  
  Downloading: 16 kB     
  Downloading: 16 kB     
  Downloading: 16 kB     
  Downloading: 16 kB     
  Downloading: 21 kB     
  Downloading: 21 kB     
  Downloading: 21 kB     
  Downloading: 21 kB     
  Downloading: 21 kB     
  Downloading: 21 kB     
  Downloading: 21 kB     
  Downloading: 21 kB     
  Downloading: 8.3 kB     
  Downloading: 8.3 kB     
  Downloading: 8.3 kB     
  Downloading: 8.3 kB     
  Downloading: 8.3 kB     
  Downloading: 8.3 kB     
  Downloading: 8.3 kB     
  Downloading: 8.3 kB     
  Downloading: 16 kB     
  Downloading: 16 kB     
  Downloading: 16 kB     
  Downloading: 16 kB     
  Downloading: 21 kB     
  Downloading: 21 kB     
  Downloading: 21 kB     
  Downloading: 21 kB     
  Downloading: 21 kB     
  Downloading: 21 kB     
  Downloading: 21 kB     
  Downloading: 21 kB     
  Downloading: 16 kB     
  Downloading: 16 kB     
  Downloading: 20 kB     
  Downloading: 20 kB     
  Downloading: 20 kB     
  Downloading: 20 kB     
  Downloading: 20 kB     
  Downloading: 20 kB     
  Downloading: 20 kB     
  Downloading: 20 kB     
  Downloading: 20 kB     
  Downloading: 20 kB     
  Downloading: 3.5 kB     
  Downloading: 3.5 kB     
  Downloading: 3.5 kB     
  Downloading: 3.5 kB     
  Downloading: 3.5 kB     
  Downloading: 3.5 kB     
  Downloading: 3.5 kB     
  Downloading: 3.5 kB     
  Downloading: 3.5 kB     
  Downloading: 3.5 kB     
  Downloading: 3.5 kB     
  Downloading: 3.5 kB     
  Downloading: 3.5 kB     
  Downloading: 3.5 kB     
  Downloading: 3.5 kB     
  Downloading: 3.5 kB     
  Downloading: 3.5 kB     
  Downloading: 3.5 kB     
  Downloading: 3.5 kB     
  Downloading: 3.5 kB     
  Downloading: 3.5 kB     
  Downloading: 3.5 kB     
  Downloading: 3.5 kB     
  Downloading: 3.5 kB     ══ testthat results  ═══════════════════════════════════════════════════════════
  OK: 58 SKIPPED: 0 FAILED: 1
  1. Error: remote mongo access (@testfunctions.R#115) 
  
  Error: testthat unit tests failed
  Execution halted