From e820643b339dad46a8a56fa2ecc72b57079f663f Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Wed, 31 Jul 2024 10:23:04 -0700 Subject: [PATCH 01/24] offlineMode updates --- DESCRIPTION | 4 +- NEWS.md | 6 + R/Require-helpers.R | 178 +++++++++++++----- R/Require2.R | 174 +++++++++++------ R/RequireOptions.R | 2 + R/messages.R | 10 + R/pkgDep.R | 27 +-- R/pkgDep3.R | 172 ++++++++++------- tests/testthat/helper_0.R | 1 - tests/testthat/test-00pkgSnapshot_testthat.R | 5 +- tests/testthat/test-01packages_testthat.R | 6 +- tests/testthat/test-04other_testthat.R | 19 +- tests/testthat/test-05packagesLong_testthat.R | 3 + tests/testthat/test-06pkgDep_testthat.R | 3 + tests/testthat/test-08modules_testthat.R | 2 + .../test-09pkgSnapshotLong_testthat.R | 1 + .../testthat/test-10DifferentPkgs_testthat.R | 1 + tests/testthat/test-11misc_testthat.R | 5 +- 18 files changed, 411 insertions(+), 208 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ed083a35..1f8f732d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -15,8 +15,8 @@ Description: A single key function, 'Require' that makes rerun-tolerant URL: https://Require.predictiveecology.org, https://github.com/PredictiveEcology/Require -Date: 2024-07-26 -Version: 1.0.0.9002 +Date: 2024-07-31 +Version: 1.0.0.9003 Authors@R: c( person(given = "Eliot J B", family = "McIntire", diff --git a/NEWS.md b/NEWS.md index d11460d1..fb6b25c9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,11 @@ # Require +version 1.0.1 +============= + +## enhancements +* `offlineMode`, which can be set using `options(Require.offlineMode = TRUE)`, but it will be automatically set if internet is not avaible, has now been widely tested. If packages are available in the local caches, and all elements of package versioning (e.g., `available.packages()` and github packages) have been previously run, then installations should occur as if the internet were availble. + version 1.0.0 ============= diff --git a/R/Require-helpers.R b/R/Require-helpers.R index 4e634d34..deeecdc7 100644 --- a/R/Require-helpers.R +++ b/R/Require-helpers.R @@ -212,19 +212,32 @@ dlGitHubFile <- function(pkg, filename = "DESCRIPTION", versionLocal <- DESCRIPTIONFileVersionV(destFile2) versionLocalOK <- rep(TRUE, length(versionLocal)) # no versionSpec will give NA next; NA is "keep" anyHEAD <- (pkgDT$versionSpec[pkgDT$repoLocation == .txtGitHub][feDF] == "HEAD") - if (isTRUE(any(anyHEAD %in% TRUE))) - versionLocalOK[anyHEAD] <- FALSE hasNonHead <- anyHEAD %in% FALSE + if (isTRUE(any(anyHEAD %in% TRUE))) { + # check if it is in this call to Require or pkgDep, based on time: delete if not + stRequire <- get0("stRequire", envir = whereInStack("stRequire")) + if (!is.null(stRequire)) { + dtime <- difftime(stRequire, file.info(destFile2)[, "mtime"], units = "secs") + whThisCall <- dtime < 0 + if (any(whThisCall)) + anyHEAD[whThisCall] <- FALSE + } + versionLocalOK[anyHEAD] <- FALSE + } if (isTRUE(any(hasNonHead))) versionLocalOK <- compareVersion2(versionLocal[hasNonHead], - pkgDT$versionSpec[pkgDT$repoLocation == .txtGitHub][feDF][hasNonHead], - inequality = pkgDT$inequality[feDF][hasNonHead]) + pkgDT$versionSpec[pkgDT$repoLocation == .txtGitHub][feDF][hasNonHead], + inequality = pkgDT$inequality[feDF][hasNonHead]) versionLocalNotOK <- versionLocalOK %in% FALSE - if (isTRUE(any(versionLocalNotOK))) { + if (isTRUE(any(versionLocalNotOK)) && getOption("Require.offlineMode") %in% FALSE) { oo <- file.remove(unique(destFile2[versionLocalNotOK])) } + } else { + if (!exists("wasHere")) + wasHere <<- 0 + wasHere <<- wasHere + 1 + # destFile <- NA } - set(pkgDT, NULL, "destFile", destFile) if (!isTRUE(getOption("Require.offlineMode"))) { @@ -238,34 +251,47 @@ dlGitHubFile <- function(pkg, filename = "DESCRIPTION", } } if (any(!alreadyExists)) { - pkgDT[repoLocation == .txtGitHub & alreadyExists %in% FALSE, - filepath := { - messageVerbose(Package, "@", Branch, " downloading ", filename, verbose = verbose - 1) - ret <- NA - dl <- .downloadFileMasterMainAuth(unique(url)[1], unique(destFile)[1], - need = "master", - verbose = verbose - 1 - ) - ret <- if (!is(dl, "try-error")) { - destFile - } else { - NA - } - - ret - }, - by = c("Package", "Branch") - ] + # messageVerbose("GitHub packages: ", paste(pkgDT$packageFullName, collapse = ", "), verbose = verbose) + withCallingHandlers( # if offline + pkgDT[which(repoLocation == .txtGitHub & alreadyExists %in% FALSE), + filepath := { + messageVerbose(Package, "@", Branch, " downloading ", filename, verbose = verbose - 1) + ret <- NA + dl <- try(.downloadFileMasterMainAuth(unique(url)[1], unique(destFile)[1], + need = "master", + verbose = verbose - 1 + )) + ret <- if (!is(dl, "try-error")) { + destFile + } else { + NA + } + + ret + }, + by = c("Package", "Branch") + ], warning = function(w) { + browser() + }) } old <- grep("filepath|destFile", colnames(pkgDT), value = TRUE)[1] wh <- which(pkgDT$repoLocation == .txtGitHub) + DESCFileVals <- pkgDT[[old]][wh] if (identical("DESCRIPTION", filename)) { - set(pkgDT, wh, "DESCFile", pkgDT[[old]][wh]) + cn <- "DESCFile" + # set(pkgDT, wh, "DESCFile", pkgDT[[old]][wh]) } else { - set(pkgDT, wh, "filename", pkgDT[[old]][wh]) + cn <- "filename" + # set(pkgDT, wh, "filename", pkgDT[[old]][wh]) } + } else { + wh <- NULL + DESCFileVals <- pkgDT[["destFile"]] + cn <- "DESCFile" } + set(pkgDT, wh, "DESCFile", DESCFileVals) + pkgDT[] } else { pkg @@ -297,12 +323,16 @@ dlArchiveVersionsAvailable <- function(package, repos = getOption("repos"), verb readRDS(con) }, warning = function(e) { + options(Require.checkInternet = TRUE) setOfflineModeTRUE(verbose = verbose) list() }, - error = function(e) list() + error = function(e) { + list() + } ) - assign(archiveFile, archive, envir = pkgDepEnv()) + if (length(archive)) + assign(archiveFile, archive, envir = pkgDepEnv()) } else { archive <- get(archiveFile, envir = pkgDepEnv()) } @@ -440,7 +470,10 @@ available.packagesCached <- function(repos, purge, verbose = getOption("Require. })), 1, 20), collapse = "_") typesShort <- paste(unlist(lapply(strsplit(types, "//"), function(x) x[[1]])), collapse = "_") objNam <- paste0("availablePackages", "_", reposShort, "_", typesShort) - if (!exists(objNam, envir = pkgDepEnv()) || isTRUE(purge)) { + # existsObjNam <- exists(objNam, envir = pkgDepEnv()) + out <- get0(objNam, envir = pkgDepEnv(), inherits = FALSE) + + if (is.null(out) || NROW(out) == 0 || isTRUE(purge)) { for (type in types) { fn <- availablePackagesCachedPath(repos, type) purgeTime <- purgeBasedOnTimeSinceCached(file.info(fn)[, "mtime"]) @@ -454,16 +487,24 @@ available.packagesCached <- function(repos, purge, verbose = getOption("Require. # can be interupted and be corrupted cap[[type]] <- try(readRDS(fn), silent = TRUE) if (!is(cap[[type]], "try-error")) needNewFile <- FALSE + # This is case where the previous version is NROW 0; could have happened if internet was down or other + if (NROW(cap[[type]]) == 0) needNewFile <- TRUE } if (isTRUE(needNewFile)) { caps <- lapply(repos, function(repo) { - available.packagesWithCallingHandlers(repo, type) + available.packagesWithCallingHandlers(repo, type, verbose = verbose) }) + # cachePurge may have been used to reset the available.packages cache + val <- Sys.getenv("R_AVAILABLE_PACKAGES_CACHE_CONTROL_MAX_AGE") + if (nzchar(val)) + if (isTRUE(val == 0)) + Sys.unsetenv("R_AVAILABLE_PACKAGES_CACHE_CONTROL_MAX_AGE") + caps <- lapply(caps, as.data.table) caps <- unique(rbindlist(caps), by = c("Package", "Version", "Repository")) cap[[type]] <- caps - if (!is.null(cacheGetOptionCachePkgDir())) { + if (!is.null(cacheGetOptionCachePkgDir()) && NROW(caps) > 0) { checkPath(dirname(fn), create = TRUE) saveRDS(cap[[type]], file = fn) } @@ -473,7 +514,7 @@ available.packagesCached <- function(repos, purge, verbose = getOption("Require. assign(objNam, cap, envir = pkgDepEnv()) out <- cap } else { - out <- get(objNam, envir = pkgDepEnv(), inherits = FALSE) + } if (isFALSE(returnDataTable)) { @@ -931,6 +972,10 @@ getSHAfromGitHub <- function(acct, repo, br, verbose = getOption("Require.verbos } if (is(gitRefs, "try-error")) { + if (isTRUE(any(grepl("cannot open the connection", gitRefs)))) { + # means no internet + setOfflineModeTRUE(verbose) + } return(gitRefs) } if (length(gitRefs) > 1) { @@ -979,14 +1024,21 @@ getSHAfromGitHubMemoise <- function(...) { pe <- pkgEnv() if (getOption("Require.useMemoise", TRUE)) { dots <- list(...) - if (!exists(.txtGetSHAfromGitHub, envir = pe, inherits = FALSE)) { - loadGitHubSHAsFromDisk(verbose = dots$verbose) # puts it into the Memoise-expected location - if (!exists(.txtGetSHAfromGitHub, envir = pe, inherits = FALSE)) - pe[[.txtGetSHAfromGitHub]] <- new.env() - } ret <- NULL ss <- match.call(definition = getSHAfromGitHub) uniqueID <- paste(lapply(ss[-1], eval, envir = parent.frame()), collapse = "_") + + # Use disk storage if in Require.offlineMode + if (!exists(uniqueID, envir = pe[[.txtGetSHAfromGitHub]], inherits = FALSE) && + getOption("Require.offlineMode", FALSE)) { + fn <- getSHAFromGitHubDBFilename() + if (file.exists(fn)) { + peList <- readRDS(fn) + if (!is.null(peList[[uniqueID]])) { + pe[[.txtGetSHAfromGitHub]][[uniqueID]] <- peList[[uniqueID]] + } + } + } if (!exists(uniqueID, envir = pe[[.txtGetSHAfromGitHub]], inherits = FALSE)) { pe[[.txtGetSHAfromGitHub]][[uniqueID]] <- list() } else { @@ -1001,6 +1053,17 @@ getSHAfromGitHubMemoise <- function(...) { # Add it to the pe newObj <- list(pe[[.txtGetSHAfromGitHub]][[uniqueID]], list(input = inputs, output = ret)) pe[[.txtGetSHAfromGitHub]][[uniqueID]] <- newObj + fn <- getSHAFromGitHubDBFilename() + peList <- as.list(pe[[.txtGetSHAfromGitHub]]) + if (!file.exists(fn)) { + saveRDS(peList, file = fn) + } else { + peListExisting <- readRDS(file = fn) + peList <- modifyList(peList, peListExisting) + saveRDS(peList, file = fn) + } + + } } else { @@ -1155,9 +1218,9 @@ internetExists <- function(mess = "", verbose = getOption("Require.verbose")) { if (isFALSE(ue)) { internetMightExist <- FALSE - messageVerbose("\033[32mInternet does not appear to exist; proceeding anyway\033[39m", - verbose = verbose, verboseLevel = 2 - ) + # messageVerbose("\033[32mInternet does not appear to exist; proceeding anyway\033[39m", + # verbose = verbose, verboseLevel = 2 + # ) } assign(.txtInternetExistsTime, Sys.time(), envir = pkgEnv()) } @@ -1304,9 +1367,9 @@ masterMainHEAD <- function(url, need) { if (!is.null(urls[["FALSE"]])) { outNotMasterMain <- Map(URL = urls[["FALSE"]], MoreArgs = list(df = destfile), function(URL, df) { - if (!isTRUE(getOption("Require.offlineMode"))) { + for (tryNum in 1:2) { + if (!isTRUE(getOption("Require.offlineMode"))) { - for (tryNum in 1:2) { if (is.null(token)) { tryCatch(download.file(URL, destfile = df, quiet = TRUE),# need TRUE to hide ghp error = function(e) { @@ -1316,7 +1379,13 @@ masterMainHEAD <- function(url, need) { messageVerbose(e$message, verbose = verbose) }) } else { - a <- GETWauthThenNonAuth(url, token, verbose = verbose) + a <- try(GETWauthThenNonAuth(url, token, verbose = verbose)) + if (is(a, "try-error")) { + if (any(grepl("Could not resolve host", a))) { + warning(a) + next + } + } # a <- httr::GET(url, httr::add_headers(Authorization = token)) # if (grepl("Bad credentials", a) || grepl("404", a$status_code)) # a <- httr::GET(url, httr::add_headers()) @@ -1593,15 +1662,20 @@ RequireGitHubCacheFile <- function(pkgDT, filename) { rmEmptyFiles <- function(files, minSize = 100) { - alreadyExists <- file.exists(files) - if (any(alreadyExists)) { - fs <- file.size(files[alreadyExists]) - tooSmall <- fs < minSize - if (any(tooSmall %in% TRUE)) { - unlink(files[alreadyExists[which(tooSmall)]]) - alreadyExists[alreadyExists] <- tooSmall %in% FALSE + notNAs <- is.na(files) %in% FALSE + alreadyExists <- rep(FALSE, length(files)) + if (any(notNAs)) { + alreadyExists[notNAs] <- file.exists(files[notNAs]) + if (any(alreadyExists[notNAs])) { + fs <- file.size(files[notNAs][alreadyExists]) + tooSmall <- fs < minSize + if (any(tooSmall %in% TRUE)) { + unlink(files[alreadyExists[notNAs][which(tooSmall)]]) + alreadyExists[notNAs][alreadyExists] <- tooSmall %in% FALSE + } } } + alreadyExists } @@ -1618,7 +1692,7 @@ GETWauthThenNonAuth <- function(url, token, verbose = getOption("Require.verbose -available.packagesWithCallingHandlers <- function(repo, type) { +available.packagesWithCallingHandlers <- function(repo, type, verbose = getOption("Require.verbose")) { ignore_repo_cache <- FALSE for (attmpt in 1:2) { warns <- character() @@ -1652,6 +1726,8 @@ available.packagesWithCallingHandlers <- function(repo, type) { } } + if (any(grepl("cannot open URL", warns))) + setOfflineModeTRUE(verbose = verbose) out } diff --git a/R/Require2.R b/R/Require2.R index 33472eff..0a8a0564 100644 --- a/R/Require2.R +++ b/R/Require2.R @@ -240,14 +240,14 @@ Require <- function(packages, returnDetails = FALSE, ...) { - st <- Sys.time() + stRequire <- Sys.time() if (is.null(require)) require <- FALSE assign("hasGHP", NULL, envir = pkgEnv()) # clear GITHUB_PAT message; only once per Require session opts <- setNcpus() - checkAutomaticOfflineMode() # This will turn off offlineMode if it had been turned on automatically on.exit( { options(opts) + checkAutomaticOfflineMode() # This will turn off offlineMode if it had been turned on automatically }, add = TRUE ) @@ -440,9 +440,10 @@ Require <- function(packages, } et <- Sys.time() - et <- difftime(et, st) + et <- difftime(et, stRequire) numPacksInstalled <- NROW(pkgDT$installed[(pkgDT$installed %in% TRUE | is.na(pkgDT$installed)) & - (pkgDT$needInstall %in% .txtInstall | is.na(pkgDT$installed)) ]) + (pkgDT$needInstall %in% .txtInstall | is.na(pkgDT$installed)) & + (pkgDT$needInstall %in% .txtInstall & pkgDT$installResult %in% "OK")]) if (numPacksInstalled > 0) messageVerbose(paste0("Installed ", numPacksInstalled, " packages in "), @@ -454,6 +455,12 @@ Require <- function(packages, paste(pkgDT[["packageFullName"]][which(noneAv)], collapse = ", "))) } + noInternet <- pkgDT$installResult %in% .txtNoInternetNoLocalCantInstall + if (isTRUE(any(noInternet))) { + warning(messageCantInstallNoInternet( + paste(pkgDT[["packageFullName"]][which(noInternet)], collapse = ", "))) + } + return(invisible(out)) } @@ -601,7 +608,7 @@ installAll <- function(toInstall, repos = getOptions("repos"), purge = FALSE, in rmErroredPkgInstalls(logFile = logFile, toInstall, verbose) }, add = TRUE) - tries <- seq(1, 3) + tries <- seq(1, 2) for (attempt in tries) { toInstallOut <- try(withCallingHandlers( installPackagesWithQuiet(ipa, verbose = verbose), @@ -611,8 +618,10 @@ installAll <- function(toInstall, repos = getOptions("repos"), purge = FALSE, in invokeRestart("muffleWarning") # muffle them because if they were necessary, they were redone in `messagesAboutWarnings` } )) - if (!is(toInstallOut, "try-error")) + errorCond <- attr(toInstallOut, "condition") + if (!is(toInstallOut, "try-error") || !is.null(errorCond)) { break + } ipa <- recoverFromFail(toInstallOut, toInstall, ipa, attempt = attempt, tries = tries, repos = repos, tmpdir = tmpdir, libPaths = libPaths, @@ -673,9 +682,12 @@ doInstalls <- function(pkgDT, repos, purge, libPaths, install.packagesArgs, pkgInstallList <- split(pkgInstall, by = c("needInstall")) for (i in setdiff(names(pkgInstallList), .txtDontInstall)) pkgDTList[[i]] <- pkgInstallList[[i]] - if (!is.null(pkgInstallList[[.txtDontInstall]])) + if (!is.null(pkgInstallList[[.txtDontInstall]])) { pkgDTList[[.txtDontInstall]] <- rbindlist(list(pkgDTList[[.txtDontInstall]], pkgInstallList[[.txtDontInstall]]), fill = TRUE, use.names = TRUE) + if (getOption("Require.offlineMode")) + pkgDTList[[.txtInstall]] <- pkgDTList[[.txtInstall]][!pkgDTList[[.txtDontInstall]], on = "packageFullName"] + } if (NROW(pkgDTList[[.txtInstall]])) { pkgInstallList <- split(pkgInstall, by = "needInstall") # There are now ones that can't be installed b/c .txtNoneAvailable pkgInstall <- pkgInstallList[[.txtInstall]] @@ -1024,36 +1036,44 @@ doDownloads <- function(pkgInstall, repos, purge, verbose, install.packagesArgs, numToDownload <- NROW(pkgInstallList[[.txtNoLocal]]) if (NROW(pkgNeedInternet)) { - pkgNeedInternet <- split(pkgNeedInternet, by = "repoLocation") + if (getOption("Require.offlineMode", FALSE)) { + wh <- which(!nzchar(pkgNeedInternet[["localFile"]])) + pkgNeedInternet[wh, needInstall := .txtDontInstall] + pkgNeedInternet[wh, installResult := .txtNoInternetNoLocalCantInstall] + } else { - # CRAN - pkgNeedInternet <- downloadCRAN(pkgNeedInternet, repos, purge, install.packagesArgs, - verbose, numToDownload, - type = type, tmpdir = tmpdir - ) + pkgNeedInternet <- split(pkgNeedInternet, by = "repoLocation") - # Archive - pkgNeedInternet <- downloadArchive( - pkgNeedInternet, repos, purge = purge, install.packagesArgs, - numToDownload, tmpdir = tmpdir, verbose = verbose - 1 - ) - if (!is.null(pkgNeedInternet$Archive)) - pkgNeedInternet$Archive[nchar(localFile) == 0 | is.na(localFile), needInstall := .txtNoneAvailable] + # CRAN + pkgNeedInternet <- downloadCRAN(pkgNeedInternet, repos, purge, install.packagesArgs, + verbose, numToDownload, + type = type, tmpdir = tmpdir + ) - # GitHub - pkgNeedInternet <- downloadGitHub( - pkgNeedInternet, libPaths, tmpdir = tmpdir, verbose, install.packagesArgs, - numToDownload - ) - if (!is.null(pkgNeedInternet$GitHub)) { - if (!is.null(pkgNeedInternet$GitHub[["SHAonLocal"]])) { - pkgNeedInternet$GitHub[SHAonGH == SHAonLocal, needInstall := .txtShaUnchangedNoInstall] + # Archive + pkgNeedInternet <- downloadArchive( + pkgNeedInternet, repos, purge = purge, install.packagesArgs, + numToDownload, tmpdir = tmpdir, verbose = verbose - 1 + ) + if (!is.null(pkgNeedInternet$Archive)) + pkgNeedInternet$Archive[nchar(localFile) == 0 | is.na(localFile), needInstall := .txtNoneAvailable] + + # GitHub + pkgNeedInternet <- downloadGitHub( + pkgNeedInternet, libPaths, tmpdir = tmpdir, verbose, install.packagesArgs, + numToDownload + ) + if (!is.null(pkgNeedInternet$GitHub)) { + if (!is.null(pkgNeedInternet$GitHub[["SHAonLocal"]])) { + pkgNeedInternet$GitHub[SHAonGH == SHAonLocal, needInstall := .txtShaUnchangedNoInstall] + } + pkgNeedInternet$GitHub[(nchar(localFile) == 0 | is.na(localFile)) & needInstall != .txtShaUnchangedNoInstall, + needInstall := .txtNoneAvailable] } - pkgNeedInternet$GitHub[(nchar(localFile) == 0 | is.na(localFile)) & needInstall != .txtShaUnchangedNoInstall, - needInstall := .txtNoneAvailable] - } + } pkgInstallList[[.txtNoLocal]] <- pkgNeedInternet # pointer + } pkgInstall <- rbindlistRecursive(pkgInstallList) @@ -1177,14 +1197,18 @@ downloadCRAN <- function(pkgNoLocal, repos, purge, install.packagesArgs, verbose st <- system.time( dt <- sysInstallAndDownload(args = args, splitOn = c("url", "destfile"), - doLine = "outfiles <- do.call(download.file, args)", + doLine = "outfiles <- try(do.call(download.file, args))", tmpdir = tmpdir, verbose = verbose) ) - messageVerbose(" CRAN ", downloadedInSeconds(st[[3]]), verbose = verbose) - pkgCRAN[dt, localFile := i.localFile, on = "Package"] - pkgCRAN[availableVersionOK %in% TRUE, installFrom := .txtLocal] - pkgCRAN[availableVersionOK %in% TRUE, newLocalFile := TRUE] + if (!getOption("Require.offlineMode") %in% TRUE) { + messageVerbose(" CRAN ", downloadedInSeconds(st[[3]]), verbose = verbose) + pkgCRAN[dt, localFile := i.localFile, on = "Package"] + pkgCRAN[availableVersionOK %in% TRUE, installFrom := .txtLocal] + pkgCRAN[availableVersionOK %in% TRUE, newLocalFile := TRUE] + } else { + pkgCRAN[availableVersionOK %in% TRUE, newLocalFile := FALSE] + } } else { pkgCRAN[availableVersionOK %in% TRUE, installFrom := "CRAN"] pkgCRAN[, localFile := useRepository] @@ -1295,6 +1319,7 @@ downloadGitHub <- function(pkgNoLocal, libPaths, verbose, install.packagesArgs, pkgGitHub[avOK, (colsToUpdate) := { SHAonGH <- getSHAfromGitHubMemoise(repo = Repo, acct = Account, br = Branch, verbose = verbose) }, by = "Package"] + browser() saveGitHubSHAsToDisk() } @@ -1479,7 +1504,7 @@ localFilename <- function(pkgInstall, localFiles, libPaths, verbose) { alreadyExistingDESCFile(libPaths = libPaths, Repo, Account, Branch, installResult, verbose) }, by = "packageFullName"] } - saveGitHubSHAsToDisk() + # saveGitHubSHAsToDisk() prevInstallResult <- pkgGitHub$installResult rowsToUpdate <- which(pkgGitHub$SHAonLocal == pkgGitHub$SHAonGH & pkgGitHub[["installResult"]] == .txtShaUnchangedNoInstall) @@ -1833,22 +1858,21 @@ moveFileToCacheOrTmp <- function(pkgInstall) { } getGitHubVersionOnRepos <- function(pkgGitHub) { - if (!isTRUE(getOption("Require.offlineMode"))) { - notYet <- is.na(pkgGitHub[["VersionOnRepos"]]) - if (any(notYet)) { - pkgGitHub <- dlGitHubFile(pkgGitHub) - dFile <- pkgGitHub[["DESCFile"]] - hasDFile <- which(!is.na(dFile)) - set(pkgGitHub, hasDFile, "VersionOnRepos", DESCRIPTIONFileVersionV(dFile)) - mayNeedPackageNameChange <- DESCRIPTIONFileOtherV(dFile, other = "Package") - alreadyCorrect <- pkgGitHub[["Package"]][hasDFile] == mayNeedPackageNameChange - notAlreadyCorrect <- alreadyCorrect %in% FALSE - if (any(notAlreadyCorrect)) { - set(pkgGitHub, hasDFile[notAlreadyCorrect], "Package", mayNeedPackageNameChange[notAlreadyCorrect]) - } - # pkgGitHub[!is.na(DESCFile), VersionOnRepos := DESCRIPTIONFileVersionV(DESCFile)] - } + notYet <- is.na(pkgGitHub[["VersionOnRepos"]]) + if (any(notYet)) { + pkgGitHub <- dlGitHubFile(pkgGitHub) + dFile <- pkgGitHub[["DESCFile"]] + hasDFile <- which(!is.na(dFile)) + set(pkgGitHub, hasDFile, "VersionOnRepos", DESCRIPTIONFileVersionV(dFile)) + mayNeedPackageNameChange <- DESCRIPTIONFileOtherV(dFile, other = "Package") + alreadyCorrect <- pkgGitHub[["Package"]][hasDFile] == mayNeedPackageNameChange + notAlreadyCorrect <- alreadyCorrect %in% FALSE + if (any(notAlreadyCorrect)) { + set(pkgGitHub, hasDFile[notAlreadyCorrect], "Package", mayNeedPackageNameChange[notAlreadyCorrect]) + } + # pkgGitHub[!is.na(DESCFile), VersionOnRepos := DESCRIPTIONFileVersionV(DESCFile)] } + # } pkgGitHub } @@ -2777,6 +2801,19 @@ messagesAboutWarnings <- function(w, toInstall, returnDetails, tmpdir, verbose = .txtCannotOpenFile, sep = "|"), w$message) if (any(failedMsg)) { + if (any(grepl(.txtCannotOpenFile, w$message))) { + logFile <- dir(tmpdir, full.names = TRUE, pattern = "\\.log") + fe <- file.exists(logFile) + if (isTRUE(any(fe))) { + logFile <- head(logFile[order(file.info(logFile)[, "mtime"], decreasing = TRUE)], 1) + log <- readLines(logFile) + if (any(grepl("problem copying.*permission denied", log, ignore.case = TRUE))) { + unlink(logFile) + # warning is already done in sysDo + stop("Is some other process using ", pkgName, "?", "\nPerhaps close other R sessions?", call. = FALSE) + } + } + } unlink(toInstall[Package %in% pkgName]$localFile) unlink(dir(tmpdir, pattern = paste0("^", pkgName, "_[[:digit:]]", collapse = "|"), full.names = TRUE)) if (isTRUE(any(grepl(.txtCannotOpenFile, w$message)))) { @@ -3535,13 +3572,18 @@ sysInstallAndDownload <- function(args, splitOn = "pkgs", } fullMess <- if (length(fullMess)) paste(fullMess, mess, sep = ", ") else mess - if ( (Sys.time() - st) > 2 && nzchar(fullMess)) { - fullMess <- paste0WithLineFeed(fullMess) - messageVerbose(blue(paste0(" ", preMess, fullMess)), verbose = verbose) - fullMess <- character() + ll <- try(lapply(outfiles, readRDS), silent = TRUE) + isError <- vapply(ll, is, class2 = "try-error", FUN.VALUE = logical(1)) + if (!is(ll, "try-error") && any(!isError)) { + if ( (Sys.time() - st) > 2 && nzchar(fullMess)) { + fullMess <- paste0WithLineFeed(fullMess) + messageVerbose(blue(paste0(" ", preMess, fullMess)), verbose = verbose) + fullMess <- character() + } } } + # if (installPackages) { # sup <- Map(libFrom = libTemps, function(libFrom) { # linkOrCopyPackageFilesInner(dir(libFrom), fromLib = libFrom, toLib = argsOrig$lib) @@ -3549,13 +3591,18 @@ sysInstallAndDownload <- function(args, splitOn = "pkgs", # # } - if (length(fullMess) && nzchar(fullMess)) { + # Do it again, in case the first one was in the loop; this maybe isn't necessary + ll <- try(lapply(outfiles, readRDS), silent = TRUE) + isError <- vapply(ll, is, class2 = "try-error", FUN.VALUE = logical(1)) + + if (!is(ll, "try-error") && any(!isError)) { + if (length(fullMess) && nzchar(fullMess)) { fullMess <- gsub("\n", " ", fullMess) fullMess <- paste0WithLineFeed(fullMess) messageVerbose(blue(paste0(" ", preMess, fullMess)), verbose = verbose) + } } - ll <- try(lapply(outfiles, readRDS), silent = TRUE) if (downPack && !downFile && !installPackages) { if (downPack) dt <- as.data.table(do.call(rbind, ll)) @@ -3563,6 +3610,14 @@ sysInstallAndDownload <- function(args, splitOn = "pkgs", dt <- as.data.table(cbind(Package = argsOrig[["Package"]], do.call(rbind, ll))) setnames(dt, new = c("Package", "localFile")) } else if (downFile) { + # isError <- vapply(ll, is, class2 = "try-error", FUN.VALUE = logical(1)) + if (any(isError)) { + if (any(vapply(ll, grepl, pattern = "cannot open URL", FUN.VALUE = logical(1)))) { + setOfflineModeTRUE(verbose = verbose) + dt <- list() + return(dt) + } + } dt <- list(Package = extractPkgName(filenames = basename(argsOrig$destfile)), localFile = argsOrig$destfile) |> setDT() } else if (downAndBuildLocal) { @@ -3645,7 +3700,6 @@ archiveDownloadSys <- function(pkgArchOnly, whNotfe, tmpdir, verbose) { if (length(nonEmpties)) { args <- list(url = url[nonEmpties], destfile = file.path(tmpdir, basename(url)[nonEmpties])) - dt <- sysInstallAndDownload(args = args, splitOn = c("url", "destfile"), doLine = "outfiles <- do.call(download.file, args)", tmpdir = tmpdir, @@ -3876,7 +3930,7 @@ recoverFromFail <- function(toInstallOut, toInstall, ipa, attempt, tries, repos, # verbose = verbose - 1, returnDetails = returnDetails, # dependencies = FALSE)) # dependencies = FALSE b/c it should already have what it needs } else { - stop() + stop(toInstallOut) } } else { stop("Errors installing packages, likely due to corrupt local cache files; ", diff --git a/R/RequireOptions.R b/R/RequireOptions.R index 6453ea0e..d13cfaf1 100644 --- a/R/RequireOptions.R +++ b/R/RequireOptions.R @@ -63,6 +63,7 @@ #' @rdname RequireOptions RequireOptions <- function() { list( + Require.checkInternet = TRUE, Require.cloneFrom = NULL, Require.install = TRUE, Require.installPackagesSys = if (isMacOSX()) 0L else 2L, @@ -72,6 +73,7 @@ RequireOptions <- function() { , "Rcpp" , "RcppParallel" ), + Require.offlineMode = FALSE, Require.packageVersionFile = "packageVersions.txt", Require.purge = FALSE, Require.cachePkgDir = "default", diff --git a/R/messages.R b/R/messages.R index a29087ac..82d5e7ec 100644 --- a/R/messages.R +++ b/R/messages.R @@ -14,6 +14,8 @@ comma <- ", " .txtCntInstllDep <- "Can't install dependency" .txtConflictsWith <- "Conflicts with" +.txtNoInternetNoLocalCantInstall <- "No internet and no local copy; can't install" + .txtMissingValueWhereTFNeeded <- "missing value where TRUE/FALSE needed" .txtUnableToAccessIndex <- "unable to access index" .txtGitHub <- "GitHub" @@ -24,6 +26,7 @@ comma <- ", " .txtPakNoPkgCalledPak <- "there is no package called 'pak'" .txtUnknownArchiveType <- "unknown archive type" +.txtNoInternetTestNotRelevant <- "No internet; test not relevant" # "installation of package 'ccissr' had non-zero exit status" # "installation of 2 packages failed" .txtInstallationNonZeroExit <- "installation of.+had non-zero exit status" @@ -71,6 +74,13 @@ messageCantInstallNoVersion <- function(packagesFullName) { ) } +messageCantInstallNoInternet <- function(packagesFullName) { + turquoise( + paste(unique(packagesFullName), collapse = comma), + " ", .txtCouldNotBeInstalled, "; no internet" + ) +} + msgPleaseChangeRqdVersion <- function(Package, ineq, newVersion) { paste0(.txtPleaseChangeReqdVers, " e.g., ", diff --git a/R/pkgDep.R b/R/pkgDep.R index d1157fcc..69d84e33 100644 --- a/R/pkgDep.R +++ b/R/pkgDep.R @@ -840,14 +840,20 @@ cachePurge <- function(packages = FALSE, #' @export purgeCache <- cachePurge -dealWithCache <- function(purge, +dealWithCache <- function(purge = TRUE, checkAge = TRUE, - repos = getOption("repos")) { + repos = getOption("repos"), + force = FALSE) { if (isTRUE(getOption("Require.offlineMode"))) { purge <- FALSE checkAge <- FALSE } + if (isTRUE(force)) { + purge <- TRUE + checkAge <- TRUE + } + purgeBasedOnTime <- FALSE if (!isTRUE(purge) && isTRUE(checkAge)) { ee <- pkgEnvStartTime() @@ -855,32 +861,27 @@ dealWithCache <- function(purge, } purge <- purge || purgeBasedOnTime - if (is.null(pkgDepEnv()) ) { - # if (is.null(pkgDepEnv()) || purge) { - envPkgDepCreate() - } if (purge) { + unlink(availablePackagesCachedPath(repos, type = c("binary", "source"))) + Sys.setenv("R_AVAILABLE_PACKAGES_CACHE_CONTROL_MAX_AGE"=0) pkgEnvStartTimeCreate() - } - if (purge) { unlink(dir(RequireGitHubCacheDir(), full.names = TRUE)) # getSHAFromGItHubMemoise SHAfile <- getSHAFromGitHubDBFilename() + browser() if (isTRUE(file.exists(SHAfile))) unlink(SHAfile) purgeAvailablePackages(repos, purge) - # fn <- availablePackagesCachedPath(repos = repos, type = c("source", "binary")) - # fExists <- file.exists(fn) - # if (any(fExists)) { - # unlink(fn[fExists]) - # } # This is for pkgDep fn <- pkgDepDBFilename() unlink(fn) } + if (is.null(pkgDepEnv())) + envPkgDepCreate() + if (is.null(envPkgDepGitHubSHA())) envPkgDepGitHubSHACreate() diff --git a/R/pkgDep3.R b/R/pkgDep3.R index dcf4b3eb..734ea1a4 100644 --- a/R/pkgDep3.R +++ b/R/pkgDep3.R @@ -108,6 +108,7 @@ pkgDep <- function(packages, type = getOption("pkgType"), Additional_repositories = FALSE, ...) { + stPkgDep <- Sys.time() libPaths <- dealWithMissingLibPaths(libPaths, ...) doDeps <- if (!is.null(list(...)$dependencies)) list(...)$dependencies else NULL @@ -116,7 +117,12 @@ pkgDep <- function(packages, purge <- purgePkgDep(purge) # purge <- dealWithCache(purge) - checkAutomaticOfflineMode() # This will turn off offlineMode if it had been turned on automatically + + if (is.null(get0("stRequire", whereInStack("stRequire")))) {# if this is NOT called from Require + on.exit( + checkAutomaticOfflineMode() # This will turn off offlineMode if it had been turned on automatically + ) + } # deps <- packages if (!includeBase) { @@ -188,6 +194,7 @@ pkgDep <- function(packages, })) keepColsOuter <- c("Package", "packageFullName", "parentPackage", depsCol) + keepColsOuter <- intersect(colnames(deps), keepColsOuter) deps <- deps[, ..keepColsOuter] # trimRedundancies is better for following the deps, but it will fail to keep original # user request. Use only duplicated instead ... to keep user order @@ -197,8 +204,13 @@ pkgDep <- function(packages, } else if (simplify %in% TRUE) { # collapse or not to list of character vector pfn <- deps$packageFullName - deps <- lapply(deps[[depsCol]], function(x) x[["packageFullName"]]) + if (getOption("Require.offlineMode") && !depsCol %in% colnames(deps)) { + deps <- lapply(pfn, function(x) list(NULL)) + } else { + deps <- lapply(deps[[depsCol]], function(x) x[["packageFullName"]]) + } names(deps) <- pfn + } } } else { @@ -397,63 +409,66 @@ pkgDepCRAN <- function(pkgDT, which, repos, type, libPaths, verbose) { pkgDT <- #try( joinToAvailablePackages(pkgDT, repos, type, which, verbose) + + if (!isTRUE(getOption("Require.offlineMode") %in% FALSE)) { # if available.packages wasn't available, it turns offlineMode TRUE # ) - # if (is(pkgDT2, "try-error")) { - # o <- options() - # sc <- sys.calls() - # out <- mget(ls()) - # save(out, file = "/home/emcintir/tmp/out.rda") - # stop() - # } - # pkgDT <- pkgDT2 - - needsVersionCheck <- !is.na(pkgDT$versionSpec) # | !is.na(pkgDT$VersionOnRepos) - set(pkgDT, NULL, "availableVersionOK", NA) # default - - if (any(needsVersionCheck)) { - pkgDT <- availableVersionOK(pkgDT) - - # NOT SURE ABOUT THIS -- SHOULDN"T BE NECESSARY TO PICK THE availableVersionOKthisOne - # pkgDTVerNums <- split(pkgDT, f = needsVersionCheck) - # # setnames(pkgDTVerNums$`TRUE`, old = "Version", "VersionOnRepos") - # pkgDTVerNums$`TRUE` <- availableVersionOK(pkgDTVerNums$`TRUE`) - # # setnames(pkgDTVerNums$`TRUE`, old = "VersionOnRepos", "Version") - # set(pkgDTVerNums$`TRUE`, NULL, "keep", seq(NROW(pkgDTVerNums$`TRUE`))) - # dups <- duplicated(pkgDTVerNums$`TRUE`$Package) - # pkgDTVerNums$`TRUE`[which(dups), keep := if (any(availableVersionOK)) .I[availableVersionOKthisOne][1] else .I, by = "Package"] - # pkgDTVerNums$`TRUE` <- pkgDTVerNums$`TRUE`[na.omit(unique(pkgDTVerNums$`TRUE`$keep))] - # set(pkgDTVerNums$`TRUE`, NULL, "keep", NULL) # remove "keep" column; no longer needed - # pkgDT <- rbindlist(pkgDTVerNums, fill = TRUE) - - #, availableVersionOK := compareVersion2(Version, versionSpec, inequality)] - } else { - set(pkgDT, NULL, "availableVersionOK", TRUE) - } + # if (is(pkgDT2, "try-error")) { + # o <- options() + # sc <- sys.calls() + # out <- mget(ls()) + # save(out, file = "/home/emcintir/tmp/out.rda") + # stop() + # } + # pkgDT <- pkgDT2 + + needsVersionCheck <- !is.na(pkgDT$versionSpec) # | !is.na(pkgDT$VersionOnRepos) + set(pkgDT, NULL, "availableVersionOK", NA) # default + + if (any(needsVersionCheck)) { + pkgDT <- availableVersionOK(pkgDT) + + # NOT SURE ABOUT THIS -- SHOULDN"T BE NECESSARY TO PICK THE availableVersionOKthisOne + # pkgDTVerNums <- split(pkgDT, f = needsVersionCheck) + # # setnames(pkgDTVerNums$`TRUE`, old = "Version", "VersionOnRepos") + # pkgDTVerNums$`TRUE` <- availableVersionOK(pkgDTVerNums$`TRUE`) + # # setnames(pkgDTVerNums$`TRUE`, old = "VersionOnRepos", "Version") + # set(pkgDTVerNums$`TRUE`, NULL, "keep", seq(NROW(pkgDTVerNums$`TRUE`))) + # dups <- duplicated(pkgDTVerNums$`TRUE`$Package) + # pkgDTVerNums$`TRUE`[which(dups), keep := if (any(availableVersionOK)) .I[availableVersionOKthisOne][1] else .I, by = "Package"] + # pkgDTVerNums$`TRUE` <- pkgDTVerNums$`TRUE`[na.omit(unique(pkgDTVerNums$`TRUE`$keep))] + # set(pkgDTVerNums$`TRUE`, NULL, "keep", NULL) # remove "keep" column; no longer needed + # pkgDT <- rbindlist(pkgDTVerNums, fill = TRUE) + + #, availableVersionOK := compareVersion2(Version, versionSpec, inequality)] + } else { + set(pkgDT, NULL, "availableVersionOK", TRUE) + } - inCurrentCRAN <- inCurrentCRAN(pkgDT, verbose) - - if (any(!inCurrentCRAN)) { - set(pkgDT, which(!inCurrentCRAN), "repoLocation", "Archive") - pkgDTList <- split(pkgDT, by = "repoLocation") - dups <- duplicated(pkgDTList$Archive$Package) # b/c will hvae src and bin --> not needed any more - pkgDTList$Archive <- pkgDTList$Archive[which(!dups)] - num <- NROW(pkgDTList$Archive$Package) - messageVerbose(paste(pkgDTList$Archive$packageFullName, collapse = comma), " ", - "not on CRAN; checking CRAN archives ... ", verbose = verbose) - pkgDTList <- getArchiveDESCRIPTION(pkgDTList, repos, which, libPaths = libPaths, verbose, purge = FALSE) - wcr <- whichCatRecursive(which, recursive = FALSE) - hadArchive <- !is.na(pkgDTList$Archive$VersionOnRepos) - whHadArchive <- which(hadArchive) - didntFindOnArchives <- is.na(pkgDTList[["Archive"]]$DESCFileFull) - if (any(didntFindOnArchives)) { - messageVerbose(red(" Did not find archives of: ", - paste(pkgDTList[["Archive"]]$packageFullName[didntFindOnArchives], collapse = comma), - "\n --> Maybe version misspecified or were they installed locally?")) + inCurrentCRAN <- inCurrentCRAN(pkgDT, verbose) + + if (any(!inCurrentCRAN)) { + set(pkgDT, which(!inCurrentCRAN), "repoLocation", "Archive") + pkgDTList <- split(pkgDT, by = "repoLocation") + dups <- duplicated(pkgDTList$Archive$Package) # b/c will hvae src and bin --> not needed any more + pkgDTList$Archive <- pkgDTList$Archive[which(!dups)] + num <- NROW(pkgDTList$Archive$Package) + messageVerbose(paste(pkgDTList$Archive$packageFullName, collapse = comma), " ", + "not on CRAN; checking CRAN archives ... ", verbose = verbose) + pkgDTList <- getArchiveDESCRIPTION(pkgDTList, repos, which, libPaths = libPaths, verbose, purge = FALSE) + wcr <- whichCatRecursive(which, recursive = FALSE) + hadArchive <- !is.na(pkgDTList$Archive$VersionOnRepos) + whHadArchive <- which(hadArchive) + didntFindOnArchives <- is.na(pkgDTList[["Archive"]]$DESCFileFull) + if (any(didntFindOnArchives)) { + messageVerbose(red(" Did not find archives of: ", + paste(pkgDTList[["Archive"]]$packageFullName[didntFindOnArchives], collapse = comma), + "\n --> Maybe version misspecified or were they installed locally?")) - } + } - messageVerbose(" Done evaluating archives!", verbose = verbose) - pkgDT <- rbindlistNULL(pkgDTList, fill = TRUE, use.names = TRUE) + messageVerbose(" Done evaluating archives!", verbose = verbose) + pkgDT <- rbindlistNULL(pkgDTList, fill = TRUE, use.names = TRUE) + } } pkgDT[] @@ -463,8 +478,6 @@ pkgDepCRAN <- function(pkgDT, which, repos, type, libPaths, verbose) { #' @inheritParams Require pkgDepGitHub <- function(pkgDT, which, includeBase = FALSE, libPaths, verbose = getOption("Require.verbose")) { - messageVerbose(" ", NROW(pkgDT), " packages on GitHub", verbose = verbose) - pkg <- masterMainToHead(pkgDT$packageFullName) localVersionOK <- pkgDT$installedVersionOK @@ -576,7 +589,7 @@ getDepsGH <- function(pkgDT, verbose, which, whichCatRecursive, libPaths, doSave installedNoOKAndNoPkgEnv <- installedNoOKAndNoPkgEnv & !haveLocalSHA installedNoOKAndNoPkgEnvWh <- which(installedNoOKAndNoPkgEnv) if (length(installedNoOKAndNoPkgEnvWh)) { - shaOuts <- #try( + shaOuts <- try( # This try is for "no internet" Map( repo = pkgDT$Repo[installedNoOKAndNoPkgEnvWh], acct = pkgDT$Account[installedNoOKAndNoPkgEnvWh], @@ -584,10 +597,18 @@ getDepsGH <- function(pkgDT, verbose, which, whichCatRecursive, libPaths, doSave verbose = verbose, getSHAfromGitHubMemoise ) - # ) - if (is(shaOuts, "try-error")) + ) + if (is(shaOuts, "try-error")) { if (any(grepl(messageCantFind("|", "|", "|"), shaOuts))) stop(shaOuts) + if (any(grepl("Could not resolve host", shaOuts))) { + shaOuts <- "" + } + } + individualFails <- vapply(shaOuts, is, "try-error", FUN.VALUE = logical(1)) + if (any(individualFails)) { + shaOuts[individualFails] <- Map(sh = shaOuts[individualFails], function(sh) "") + } pkgDT[installedNoOKAndNoPkgEnvWh, shas := unlist(shaOuts)] } if (sum(installedNoOKAndNoPkgEnv %in% FALSE)) { @@ -595,16 +616,20 @@ getDepsGH <- function(pkgDT, verbose, which, whichCatRecursive, libPaths, doSave } needVersion <- needVersions(pkgDT) # if (any(needVersion)) { - descs <- dlGitHubDESCRIPTION(pkgDT)#$packageFullName) - pkgDT[descs, descFiles := DESCFile, on = "packageFullName"] - wh <- which(!is.na(pkgDT$descFiles)) - pkgDT[wh, Version := DESCRIPTIONFileVersionV(descFiles)] - possPkgUpdate <- DESCRIPTIONFileOtherV(pkgDT$descFiles[wh], other = "Package") - correctPkgName <- possPkgUpdate == pkgDT$Package[wh] - if (any(correctPkgName %in% FALSE)) { - set(pkgDT, wh, "Package", possPkgUpdate) - set(pkgDT, wh, "githubPkgName", possPkgUpdate) - } + descs <- dlGitHubDESCRIPTION(pkgDT)#$packageFullName) + pkgDT[descs, descFiles := DESCFile, on = "packageFullName"] + wh <- which(!is.na(pkgDT$descFiles)) + if (isTRUE(getOption("Require.offlineMode"))) { + fe <- file.exists(pkgDT$descFiles) + wh <- wh[fe] + } + pkgDT[wh, Version := DESCRIPTIONFileVersionV(descFiles)] + possPkgUpdate <- DESCRIPTIONFileOtherV(pkgDT$descFiles[wh], other = "Package") + correctPkgName <- possPkgUpdate == pkgDT$Package[wh] + if (any(correctPkgName %in% FALSE)) { + set(pkgDT, wh, "Package", possPkgUpdate) + set(pkgDT, wh, "githubPkgName", possPkgUpdate) + } # } break @@ -711,8 +736,13 @@ needVersions <- function(pkgDT) { updateWithRemotesNamespaceAddRepos2 <- function(pkgDT, which, purge, includeBase, verbose) { if (!"shas" %in% colnames(pkgDT)) set(pkgDT, NULL, "shas", pkgDT$Branch) + fe <- seq_len(NROW(pkgDT)) + if (isTRUE(getOption("Require.offlineMode"))) { + fe <- which(file.exists(pkgDT$DESCFile)) + } + - out <- pkgDT[, list(# packageFullName = packageFullName, + out <- pkgDT[fe, list(# packageFullName = packageFullName, lis = { allDeps <- DESCRIPTIONFileDeps(DESCFile, which = c("Depends", "Imports", "Suggests", "LinkingTo"), purge = purge, keepSeparate = TRUE) diff --git a/tests/testthat/helper_0.R b/tests/testthat/helper_0.R index 3eae1c5c..53675090 100644 --- a/tests/testthat/helper_0.R +++ b/tests/testthat/helper_0.R @@ -69,4 +69,3 @@ dontDetach <- function() { dtd } - diff --git a/tests/testthat/test-00pkgSnapshot_testthat.R b/tests/testthat/test-00pkgSnapshot_testthat.R index 3ba8d5f6..8954a402 100644 --- a/tests/testthat/test-00pkgSnapshot_testthat.R +++ b/tests/testthat/test-00pkgSnapshot_testthat.R @@ -15,10 +15,12 @@ test_that("test 1", { tmpdirActual <- .libPaths()[1] # setLibPaths postpends the R version suppressWarnings(Require(c("rlang"), require = FALSE, quiet = quiet)) + skip_if_offline() + setLibPaths(tmpdir2, standAlone = TRUE) tmpdir2Actual <- .libPaths()[1] # setLibPaths postpends the R version if (isDev) { - warns <- capture_warnings(Require(c("covr (==3.6.3)"), require = FALSE, quiet = quiet)) + warns <- capture_warnings(Require(c("rlang", "covr (==3.6.3)"), require = FALSE, quiet = quiet)) test <- testWarnsInUsePleaseChange(warns) if (!isMacOSX()) expect_true(test) @@ -26,6 +28,7 @@ test_that("test 1", { Require(c("crayon"), require = FALSE, quiet = quiet) } + skip_if_offline() .libPaths(c(tmpdirActual, tmpdir2Actual)) # .libPaths(c(tmpdir, tmpdir2)) aa1 <- pkgSnapshot(packageVersionFile = pkgVF, diff --git a/tests/testthat/test-01packages_testthat.R b/tests/testthat/test-01packages_testthat.R index c43c162e..430e386c 100644 --- a/tests/testthat/test-01packages_testthat.R +++ b/tests/testthat/test-01packages_testthat.R @@ -28,11 +28,15 @@ test_that("test 1", { dir1 <- Require:::rpackageFolder(Require:::tempdir3("test1")) dir1 <- Require::checkPath(dir1, create = TRUE) - (out <- suppressMessages(Require::Require("fpCompare (<= 1.2.3)", + + (mess <- capture_messages(out <- Require::Require("fpCompare (<= 1.2.3)", standAlone = TRUE, libPaths = dir1, # quiet = TRUE, returnDetails = TRUE ))) |> capture_warnings() -> warns + + skip_if_offline() + if (length(warns)) expect_true(all(grepl("was built under", warns))) diff --git a/tests/testthat/test-04other_testthat.R b/tests/testthat/test-04other_testthat.R index 3d8be91b..4bd324ce 100644 --- a/tests/testthat/test-04other_testthat.R +++ b/tests/testthat/test-04other_testthat.R @@ -1,7 +1,7 @@ test_that("test 3", { setupInitial <- setupTest() - # on.exit(endTest(setupInitial)) + # on.exit(endTest(setupInitial)) isDev <- getOption("Require.isDev") # Test misspelled @@ -28,16 +28,21 @@ test_that("test 3", { pkgDep("data.table", purge = TRUE) } + skip_if_offline() if (isTRUE(tryCatch(packageVersion("fpCompare"), error = function(e) "0.0.0") < "0.2.5")) { if (isDev) { - Require::Install(c("fpCompare (>= 0.2.4)", "PredictiveEcology/fpCompare@development (>= 0.2.4.9000)"), - install= "force", libPaths = .libPaths()[1]) - expect_true(packVer("fpCompare", lib.loc = .libPaths()[1]) > "0.2.4") + mess <- capture_messages( + warns <- capture_warnings( + Require::Install(c("fpCompare (>= 0.2.4)", "PredictiveEcology/fpCompare@development (>= 0.2.4.9000)"), + install= "force", libPaths = .libPaths()[1]) + ) + ) + if (!isTRUE(any(grepl("Internet.+unavailable", mess)))) + expect_true(packVer("fpCompare", lib.loc = .libPaths()[1]) > "0.2.4") } } - # pkgDep2("Require") - + skip_if_offline() if (!getOption("Require.usePak", TRUE)) { pkgDepTopoSort(c("data.table"), useAllInSearch = TRUE) @@ -213,7 +218,7 @@ test_that("test 3", { expect_false(isTRUE(grepl(.txtMsgIsInUse, warnsAfter))) } warns <- capture_warnings( # fpCompare namespace cannot be unloaded: cannot open file? - # and also restarting interuupted promise evaluation + # and also restarting interuupted promise evaluation try(detach("package:fpCompare", unload = TRUE), silent = TRUE) # some are not attaching ) } diff --git a/tests/testthat/test-05packagesLong_testthat.R b/tests/testthat/test-05packagesLong_testthat.R index 4fef7d3a..801a8723 100644 --- a/tests/testthat/test-05packagesLong_testthat.R +++ b/tests/testthat/test-05packagesLong_testthat.R @@ -17,11 +17,14 @@ test_that("test 5", { opts <- options(repos = PEUniverseRepo()); on.exit(options(opts), add = TRUE) pkgDepTest1 <- Require::pkgDep("Require", includeSelf = FALSE, includeBase = FALSE) + skip_if_offline() + pkgDepTest2 <- Require::pkgDep2(c("Require"), # simplify = FALSE, # which = c("Depends", "Imports"), includeSelf = FALSE) orig <- Require::setLibPaths(tmpdir, standAlone = TRUE, updateRprofile = FALSE) + skip_if_offline() testthat::expect_true({ length(pkgDepTest1) == 1 }) diff --git a/tests/testthat/test-06pkgDep_testthat.R b/tests/testthat/test-06pkgDep_testthat.R index ac2abb12..8d15c8e2 100644 --- a/tests/testthat/test-06pkgDep_testthat.R +++ b/tests/testthat/test-06pkgDep_testthat.R @@ -13,6 +13,9 @@ test_that("test 6", { testthat::expect_true({ length(a) == 1 }) + + skip_if_offline() + testthat::expect_true({ !isTRUE(all.equal(lapply(a, trimVersionNumber), a)) }) diff --git a/tests/testthat/test-08modules_testthat.R b/tests/testthat/test-08modules_testthat.R index e18ace54..29eee67a 100644 --- a/tests/testthat/test-08modules_testthat.R +++ b/tests/testthat/test-08modules_testthat.R @@ -18,6 +18,8 @@ test_that("test 8", { # Install 3 packages that are needed for subsequent module and package installations # See if Require is already loaded from where#Error in `loadNamespace(name)`: there is no package called 'SpaDES.project' + skip_if_offline() + if (isWindows()) { (Install("Require", repos = "https://predictiveecology.r-univierse.dev", install = "force")) |> diff --git a/tests/testthat/test-09pkgSnapshotLong_testthat.R b/tests/testthat/test-09pkgSnapshotLong_testthat.R index d3cbbad4..6b2983bd 100644 --- a/tests/testthat/test-09pkgSnapshotLong_testthat.R +++ b/tests/testthat/test-09pkgSnapshotLong_testthat.R @@ -195,6 +195,7 @@ test_that("test 09", { # NLMR because the version number doesn't exist on CRAn archives # and visualTest which is missing GitHub info for some reason -- + skip_if_offline() expect_true(identical(setdiff(missingPackages$Package, knownFails), character(0))) warns <- capture_warnings( lala <- capture.output(type = "message", { diff --git a/tests/testthat/test-10DifferentPkgs_testthat.R b/tests/testthat/test-10DifferentPkgs_testthat.R index c176a36e..5811eda2 100644 --- a/tests/testthat/test-10DifferentPkgs_testthat.R +++ b/tests/testthat/test-10DifferentPkgs_testthat.R @@ -33,6 +33,7 @@ test_that("test 10", { warns <- grep("installation of package.+cissr.+had non-zero exit status", invert = TRUE, warns) test <- testWarnsInUsePleaseChange(warns) expect_true(test) + skip_if_offline() ins <- installed.packages(noCache = TRUE) |> as.data.table() notInstalled <- setdiff(extractPkgName(pkgs), ins$Package) diff --git a/tests/testthat/test-11misc_testthat.R b/tests/testthat/test-11misc_testthat.R index 0d3176d6..448cfea0 100644 --- a/tests/testthat/test-11misc_testthat.R +++ b/tests/testthat/test-11misc_testthat.R @@ -26,9 +26,12 @@ test_that("test 5b", { # This one fails to install SpaDES.core because already loaded poss2 <- sum(pkgsClean %in% ip[, "Package"]) == length(pkgsClean) - length(acceptableFails) ## TODO: fails on macOS - expect_true(poss1 || poss2) + if (internetExists()) + expect_true(poss1 || poss2) } + skip_if_offline() + ## Test Install and also (HEAD) messToSilence <- capture_messages(try(remove.packages("fpCompare"), silent = TRUE)) capted1 <- capture_messages( From b1f73b3f83fa2b3d185b764f1d6c8fa657537c01 Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Wed, 31 Jul 2024 16:35:11 -0700 Subject: [PATCH 02/24] ? colnamesInt(i, unname(on), check_dups = FALSE)`: argument specifying columns received non-existing column(s): cols[1]='V1' --- DESCRIPTION | 2 +- R/Require-helpers.R | 4 +--- R/Require2.R | 6 +++--- R/pkgDep.R | 1 - 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1f8f732d..a5905329 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -16,7 +16,7 @@ URL: https://Require.predictiveecology.org, https://github.com/PredictiveEcology/Require Date: 2024-07-31 -Version: 1.0.0.9003 +Version: 1.0.0.9004 Authors@R: c( person(given = "Eliot J B", family = "McIntire", diff --git a/R/Require-helpers.R b/R/Require-helpers.R index deeecdc7..5789901e 100644 --- a/R/Require-helpers.R +++ b/R/Require-helpers.R @@ -233,9 +233,7 @@ dlGitHubFile <- function(pkg, filename = "DESCRIPTION", oo <- file.remove(unique(destFile2[versionLocalNotOK])) } } else { - if (!exists("wasHere")) - wasHere <<- 0 - wasHere <<- wasHere + 1 + # NOT CLEAR WHAT SHOULD BE PUT HERE # destFile <- NA } set(pkgDT, NULL, "destFile", destFile) diff --git a/R/Require2.R b/R/Require2.R index 0a8a0564..56d56d0d 100644 --- a/R/Require2.R +++ b/R/Require2.R @@ -1149,6 +1149,7 @@ getVersionOnRepos <- function(pkgInstall, repos, purge, libPaths, type = getOpti downloadCRAN <- function(pkgNoLocal, repos, purge, install.packagesArgs, verbose, numToDownload, tmpdir, type = getOption("pkgType")) { pkgCRAN <- pkgNoLocal[["CRAN"]] + # browser() if (NROW(pkgCRAN)) { # CRAN, Archive, RSPM # messageVerbose(messageDownload(pkgCRAN, NROW(pkgCRAN), "CRAN"), verbose = verbose, verboseLevel = 2) if (!all(apCachedCols %in% colnames(pkgCRAN))) { @@ -1203,7 +1204,7 @@ downloadCRAN <- function(pkgNoLocal, repos, purge, install.packagesArgs, verbose ) if (!getOption("Require.offlineMode") %in% TRUE) { messageVerbose(" CRAN ", downloadedInSeconds(st[[3]]), verbose = verbose) - pkgCRAN[dt, localFile := i.localFile, on = "Package"] + pkgCRAN[availableVersionOK %in% TRUE][dt, localFile := i.localFile, on = "Package"] pkgCRAN[availableVersionOK %in% TRUE, installFrom := .txtLocal] pkgCRAN[availableVersionOK %in% TRUE, newLocalFile := TRUE] } else { @@ -1319,8 +1320,7 @@ downloadGitHub <- function(pkgNoLocal, libPaths, verbose, install.packagesArgs, pkgGitHub[avOK, (colsToUpdate) := { SHAonGH <- getSHAfromGitHubMemoise(repo = Repo, acct = Account, br = Branch, verbose = verbose) }, by = "Package"] - browser() - saveGitHubSHAsToDisk() + # saveGitHubSHAsToDisk() } pkgGHList <- split(pkgGitHub, pkgGitHub$availableVersionOK) diff --git a/R/pkgDep.R b/R/pkgDep.R index 69d84e33..fad95178 100644 --- a/R/pkgDep.R +++ b/R/pkgDep.R @@ -868,7 +868,6 @@ dealWithCache <- function(purge = TRUE, unlink(dir(RequireGitHubCacheDir(), full.names = TRUE)) # getSHAFromGItHubMemoise SHAfile <- getSHAFromGitHubDBFilename() - browser() if (isTRUE(file.exists(SHAfile))) unlink(SHAfile) From 4361fc71f51294cbfe74bf440a6bf573d1b471e3 Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Wed, 31 Jul 2024 16:58:52 -0700 Subject: [PATCH 03/24] try without data join? --- R/Require2.R | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/R/Require2.R b/R/Require2.R index 56d56d0d..64bc5393 100644 --- a/R/Require2.R +++ b/R/Require2.R @@ -1204,7 +1204,15 @@ downloadCRAN <- function(pkgNoLocal, repos, purge, install.packagesArgs, verbose ) if (!getOption("Require.offlineMode") %in% TRUE) { messageVerbose(" CRAN ", downloadedInSeconds(st[[3]]), verbose = verbose) - pkgCRAN[availableVersionOK %in% TRUE][dt, localFile := i.localFile, on = "Package"] + ord <- match(pkgCRAN$Package[pkgCRAN$availableVersionOK %in% TRUE], dt$Package) + if (FALSE) { #error on GitHub Actions: colnamesInt(i, unname(on), check_dups = FALSE)`: argument specifying columns received non-existing column(s): cols[1]='V1' + pp <- data.table::copy(pkgCRAN) + pp[availableVersionOK %in% TRUE, localFile := dt[ord]$localFile] + pkgCRAN[dt, localFile := i.localFile, on = "Package"] + if (!all(pp$Package == pkgCRAN[availableVersionOK %in% TRUE]$Package)) + browser() + } + pkgCRAN[availableVersionOK %in% TRUE, localFile := dt[ord]$localFile] pkgCRAN[availableVersionOK %in% TRUE, installFrom := .txtLocal] pkgCRAN[availableVersionOK %in% TRUE, newLocalFile := TRUE] } else { From 912c8e16eb137a7169fbfec17e3508fd33d5eef3 Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Wed, 31 Jul 2024 17:11:08 -0700 Subject: [PATCH 04/24] another try to deal with GHA --- DESCRIPTION | 2 +- R/Require2.R | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index a5905329..22ffab09 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -16,7 +16,7 @@ URL: https://Require.predictiveecology.org, https://github.com/PredictiveEcology/Require Date: 2024-07-31 -Version: 1.0.0.9004 +Version: 1.0.0.9005 Authors@R: c( person(given = "Eliot J B", family = "McIntire", diff --git a/R/Require2.R b/R/Require2.R index 64bc5393..a574597e 100644 --- a/R/Require2.R +++ b/R/Require2.R @@ -3620,11 +3620,15 @@ sysInstallAndDownload <- function(args, splitOn = "pkgs", } else if (downFile) { # isError <- vapply(ll, is, class2 = "try-error", FUN.VALUE = logical(1)) if (any(isError)) { + dt <- list(Package = extractPkgName(filenames = basename(argsOrig$destfile)), + localFile = argsOrig$destfile) if (any(vapply(ll, grepl, pattern = "cannot open URL", FUN.VALUE = logical(1)))) { setOfflineModeTRUE(verbose = verbose) - dt <- list() - return(dt) + } else { + # pull the plug and run without sys -- this seems to be failing on GA + eval(parse(text = doLine)) } + return(dt) } dt <- list(Package = extractPkgName(filenames = basename(argsOrig$destfile)), localFile = argsOrig$destfile) |> setDT() From 15243c6f6f95482067631794ba5a71759cf79a93 Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Wed, 31 Jul 2024 17:35:00 -0700 Subject: [PATCH 05/24] add rlang to Suggests --- DESCRIPTION | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 22ffab09..0838b768 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -16,7 +16,7 @@ URL: https://Require.predictiveecology.org, https://github.com/PredictiveEcology/Require Date: 2024-07-31 -Version: 1.0.0.9005 +Version: 1.0.0.9006 Authors@R: c( person(given = "Eliot J B", family = "McIntire", @@ -52,6 +52,7 @@ Suggests: rematch2, rmarkdown, knitr, + rlang, roxygen2, rprojroot, testthat (>= 3.0.0), From 5f09804bb7d4445db26038d6e2f305f69393c37f Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Wed, 31 Jul 2024 18:21:00 -0700 Subject: [PATCH 06/24] try skipping sysInstall... when ap is NROW 0 --- R/Require2.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/R/Require2.R b/R/Require2.R index a574597e..120090fd 100644 --- a/R/Require2.R +++ b/R/Require2.R @@ -1172,8 +1172,9 @@ downloadCRAN <- function(pkgNoLocal, repos, purge, install.packagesArgs, verbose if (NROW(pkgCRAN)) { pkgCRAN <- updateReposForSrcPkgs(pkgCRAN, verbose = verbose) - if (getOption("Require.installPackagesSys") == 2) { - ap <- pkgCRAN[pkgCRAN$availableVersionOK %in% TRUE] + ap <- pkgCRAN[pkgCRAN$availableVersionOK %in% TRUE] + if (getOption("Require.installPackagesSys") == 2 && NROW(ap)) { + # ap <- pkgCRAN[pkgCRAN$availableVersionOK %in% TRUE] args <- list(repos = repos, type = type) file <- paste0(ap[["Package"]], "_", ap$VersionOnRepos) if (isWindows() && (identical(type, "both") || grepl("bin", type))) { From 69135fc11adc0decd50bf9dc69648e762568127a Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Wed, 31 Jul 2024 20:51:04 -0700 Subject: [PATCH 07/24] again --- R/Require2.R | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/R/Require2.R b/R/Require2.R index 120090fd..8a8f65f6 100644 --- a/R/Require2.R +++ b/R/Require2.R @@ -3620,23 +3620,21 @@ sysInstallAndDownload <- function(args, splitOn = "pkgs", setnames(dt, new = c("Package", "localFile")) } else if (downFile) { # isError <- vapply(ll, is, class2 = "try-error", FUN.VALUE = logical(1)) + dt <- list(Package = extractPkgName(filenames = basename(argsOrig$destfile)), + localFile = argsOrig$destfile) |> as.data.table() if (any(isError)) { - dt <- list(Package = extractPkgName(filenames = basename(argsOrig$destfile)), - localFile = argsOrig$destfile) if (any(vapply(ll, grepl, pattern = "cannot open URL", FUN.VALUE = logical(1)))) { setOfflineModeTRUE(verbose = verbose) } else { # pull the plug and run without sys -- this seems to be failing on GA eval(parse(text = doLine)) } - return(dt) } - dt <- list(Package = extractPkgName(filenames = basename(argsOrig$destfile)), - localFile = argsOrig$destfile) |> setDT() + return(dt) } else if (downAndBuildLocal) { dt <- list(Package = argsOrig[["Package"]], - localFile = unlist(ll)) - setDT(dt) + localFile = unlist(ll)) |> as.data.table() + # setDT(dt) # if (length(dt$localFile) != length(dt$Package)) # dt$localFile <- rep("", length(dt$Package)) # a <- try(setDT(dt), silent = TRUE) From e98cebb909cdeda6b2cbd7cfeac3b8fbc45a9dc5 Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Wed, 31 Jul 2024 20:58:21 -0700 Subject: [PATCH 08/24] revert remove join --- R/Require2.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/Require2.R b/R/Require2.R index 8a8f65f6..d4d9a7bd 100644 --- a/R/Require2.R +++ b/R/Require2.R @@ -1205,7 +1205,7 @@ downloadCRAN <- function(pkgNoLocal, repos, purge, install.packagesArgs, verbose ) if (!getOption("Require.offlineMode") %in% TRUE) { messageVerbose(" CRAN ", downloadedInSeconds(st[[3]]), verbose = verbose) - ord <- match(pkgCRAN$Package[pkgCRAN$availableVersionOK %in% TRUE], dt$Package) + # ord <- match(pkgCRAN$Package[pkgCRAN$availableVersionOK %in% TRUE], dt$Package) if (FALSE) { #error on GitHub Actions: colnamesInt(i, unname(on), check_dups = FALSE)`: argument specifying columns received non-existing column(s): cols[1]='V1' pp <- data.table::copy(pkgCRAN) pp[availableVersionOK %in% TRUE, localFile := dt[ord]$localFile] @@ -1213,7 +1213,8 @@ downloadCRAN <- function(pkgNoLocal, repos, purge, install.packagesArgs, verbose if (!all(pp$Package == pkgCRAN[availableVersionOK %in% TRUE]$Package)) browser() } - pkgCRAN[availableVersionOK %in% TRUE, localFile := dt[ord]$localFile] + pkgCRAN[dt, localFile := i.localFile, on = "Package"] + # pkgCRAN[availableVersionOK %in% TRUE, localFile := dt[ord, ]$localFile] pkgCRAN[availableVersionOK %in% TRUE, installFrom := .txtLocal] pkgCRAN[availableVersionOK %in% TRUE, newLocalFile := TRUE] } else { @@ -3619,7 +3620,6 @@ sysInstallAndDownload <- function(args, splitOn = "pkgs", dt <- as.data.table(cbind(Package = argsOrig[["Package"]], do.call(rbind, ll))) setnames(dt, new = c("Package", "localFile")) } else if (downFile) { - # isError <- vapply(ll, is, class2 = "try-error", FUN.VALUE = logical(1)) dt <- list(Package = extractPkgName(filenames = basename(argsOrig$destfile)), localFile = argsOrig$destfile) |> as.data.table() if (any(isError)) { From bb17ce4e5fda72b34b3243beeca508bff82b761f Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Wed, 31 Jul 2024 21:08:35 -0700 Subject: [PATCH 09/24] finalizing gcc fails --- DESCRIPTION | 2 +- R/Require2.R | 18 ++---------------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0838b768..7d4aed9d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -16,7 +16,7 @@ URL: https://Require.predictiveecology.org, https://github.com/PredictiveEcology/Require Date: 2024-07-31 -Version: 1.0.0.9006 +Version: 1.0.0.9007 Authors@R: c( person(given = "Eliot J B", family = "McIntire", diff --git a/R/Require2.R b/R/Require2.R index d4d9a7bd..97f301a8 100644 --- a/R/Require2.R +++ b/R/Require2.R @@ -3630,25 +3630,11 @@ sysInstallAndDownload <- function(args, splitOn = "pkgs", eval(parse(text = doLine)) } } - return(dt) + # return(dt) } else if (downAndBuildLocal) { dt <- list(Package = argsOrig[["Package"]], localFile = unlist(ll)) |> as.data.table() - # setDT(dt) - # if (length(dt$localFile) != length(dt$Package)) - # dt$localFile <- rep("", length(dt$Package)) - # a <- try(setDT(dt), silent = TRUE) - # if (is(a, 'try-error')) { - # # out <- mget(ls()) - # # out$token <- tryCatch( - # # gitcreds::gitcreds_get(use_cache = FALSE), - # # error = function(e) NULL - # # ) - # # - # # save(out, file = "/home/emcintir/tmp/dt.rda") - # stop(a) - # } - } else { # installPackages and Other + } else { # installPackages and Other -- expecting on logFile as a character string dt <- logFile } From dd91ef2043d50c791b0b6d1dd046462ad736a526 Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Wed, 31 Jul 2024 21:11:57 -0700 Subject: [PATCH 10/24] loadOrder not necessary if `require` = FALSE --- R/Require2.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/Require2.R b/R/Require2.R index 97f301a8..8232c2f9 100644 --- a/R/Require2.R +++ b/R/Require2.R @@ -905,7 +905,7 @@ doLoads <- function(require, pkgDT, libPaths, verbose = getOption("Require.verbo } else if (isTRUE(require)) { pkgDT[!is.na(loadOrder), require := TRUE] } else if (isFALSE(require)) { - pkgDT[!is.na(loadOrder), require := FALSE] + set(pkgDT, NULL, "require", FALSE) } # override if version was not OK From ee5903aca1c6f1235944424ebf380dc72e14604a Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Wed, 31 Jul 2024 21:24:58 -0700 Subject: [PATCH 11/24] with prev --- R/Require2.R | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/R/Require2.R b/R/Require2.R index 8232c2f9..15538760 100644 --- a/R/Require2.R +++ b/R/Require2.R @@ -890,7 +890,7 @@ whichToInstall <- function(pkgDT, install, verbose) { verbose = verbose, verboseLevel = 1) } if (identical(install, "force")) { - askedByUser <- !is.na(pkgDT$loadOrder) + askedByUser <- !is.na(pkgDT[["loadOrder"]]) set(pkgDT, which(askedByUser), "needInstall", .txtInstall) } @@ -902,10 +902,9 @@ doLoads <- function(require, pkgDT, libPaths, verbose = getOption("Require.verbo needRequire <- require if (is.character(require)) { pkgDT[Package %in% require, require := TRUE] - } else if (isTRUE(require)) { - pkgDT[!is.na(loadOrder), require := TRUE] - } else if (isFALSE(require)) { - set(pkgDT, NULL, "require", FALSE) + } else { + wh <- if (is.null(pkgDT[["loadOrder"]])) seq_len(NROW(pkgDT)) else which(!is.na(pkgDT[["loadOrder"]])) + pkgDT[wh, require := isTRUE(require)] } # override if version was not OK @@ -928,7 +927,7 @@ doLoads <- function(require, pkgDT, libPaths, verbose = getOption("Require.verbo out[[2]] <- mapply(x = pkgDT[["Package"]][pkgDT$require %in% FALSE], function(x) FALSE, USE.NAMES = TRUE) } out <- do.call(c, out) - out[na.omit(pkgDT[["Package"]][!is.na(pkgDT$loadOrder)])] # put in order, based on loadOrder + out[na.omit(pkgDT[["Package"]][!is.na(pkgDT[["loadOrder"]])])] # put in order, based on loadOrder out } From d14ce9e0f4d72f1bc18384b351a280eda60e5904 Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Wed, 31 Jul 2024 21:51:08 -0700 Subject: [PATCH 12/24] tweaks --- R/Require-helpers.R | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/R/Require-helpers.R b/R/Require-helpers.R index 5789901e..bed329f0 100644 --- a/R/Require-helpers.R +++ b/R/Require-helpers.R @@ -1053,12 +1053,14 @@ getSHAfromGitHubMemoise <- function(...) { pe[[.txtGetSHAfromGitHub]][[uniqueID]] <- newObj fn <- getSHAFromGitHubDBFilename() peList <- as.list(pe[[.txtGetSHAfromGitHub]]) - if (!file.exists(fn)) { - saveRDS(peList, file = fn) - } else { - peListExisting <- readRDS(file = fn) - peList <- modifyList(peList, peListExisting) - saveRDS(peList, file = fn) + if (length(fn)) { # this can be character() if cacheGetOptionCachePkgDir() is NULL + if (!isTRUE(file.exists(fn)) {) + saveRDS(peList, file = fn) + } else { + peListExisting <- readRDS(file = fn) + peList <- modifyList(peList, peListExisting) + saveRDS(peList, file = fn) + } } From 79d46a66836b2c2daf40efe2f1835cb112a5fb65 Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Thu, 1 Aug 2024 07:09:28 -0700 Subject: [PATCH 13/24] whoops --- R/Require-helpers.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/Require-helpers.R b/R/Require-helpers.R index bed329f0..394946e8 100644 --- a/R/Require-helpers.R +++ b/R/Require-helpers.R @@ -1054,7 +1054,7 @@ getSHAfromGitHubMemoise <- function(...) { fn <- getSHAFromGitHubDBFilename() peList <- as.list(pe[[.txtGetSHAfromGitHub]]) if (length(fn)) { # this can be character() if cacheGetOptionCachePkgDir() is NULL - if (!isTRUE(file.exists(fn)) {) + if (!isTRUE(file.exists(fn))) { saveRDS(peList, file = fn) } else { peListExisting <- readRDS(file = fn) From 599ac9af78eec0c0903240fe55af83a591115e20 Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Thu, 1 Aug 2024 07:39:59 -0700 Subject: [PATCH 14/24] try macosx without sys --- R/Require-helpers.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/Require-helpers.R b/R/Require-helpers.R index 394946e8..95dbfb17 100644 --- a/R/Require-helpers.R +++ b/R/Require-helpers.R @@ -1533,7 +1533,7 @@ installPackagesWithQuiet <- function(ipa, verbose) { ipa$type <- ipa$type[2] if (getOption("Require.installPackagesSys") && - requireNamespace("sys", quietly = TRUE)){ + requireNamespace("sys", quietly = TRUE) && !isMacOSX()){ for (i in 1:1) { anyFailed <- NULL out <- #try( From f731b4325ea05dea4dca62d57dd7dc42572cd195 Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Thu, 1 Aug 2024 07:54:37 -0700 Subject: [PATCH 15/24] again --- R/Require-helpers.R | 2 +- tests/testthat/setup.R | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/R/Require-helpers.R b/R/Require-helpers.R index 95dbfb17..394946e8 100644 --- a/R/Require-helpers.R +++ b/R/Require-helpers.R @@ -1533,7 +1533,7 @@ installPackagesWithQuiet <- function(ipa, verbose) { ipa$type <- ipa$type[2] if (getOption("Require.installPackagesSys") && - requireNamespace("sys", quietly = TRUE) && !isMacOSX()){ + requireNamespace("sys", quietly = TRUE)){ for (i in 1:1) { anyFailed <- NULL out <- #try( diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R index 53cf44a8..ae9fdded 100644 --- a/tests/testthat/setup.R +++ b/tests/testthat/setup.R @@ -1,9 +1,9 @@ if (.isDevelVersion() && nchar(Sys.getenv("R_REQUIRE_RUN_ALL_TESTS")) == 0) { Sys.setenv("R_REQUIRE_RUN_ALL_TESTS" = "true") } -verboseForDev <- -2 +verboseForDev <- 2 Require.usePak <- FALSE -Require.installPackageSys <- 2 +Require.installPackageSys <- 2 * (isMacOSX() %in% FALSE) if (isTRUE(Require.usePak)) if (requireNamespace("pak")) From be6e39218b3ee058afb616eedcf4ff58e511253f Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Thu, 1 Aug 2024 08:11:41 -0700 Subject: [PATCH 16/24] more for Mac --- R/pkgDep3.R | 7 ++++++- tests/testthat/setup.R | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/R/pkgDep3.R b/R/pkgDep3.R index 734ea1a4..41a3bc9d 100644 --- a/R/pkgDep3.R +++ b/R/pkgDep3.R @@ -645,7 +645,12 @@ getDepsGH <- function(pkgDT, verbose, which, whichCatRecursive, libPaths, doSave out <- pkgDepGitHub(pkgDT = pkgDT, which = which, includeBase = FALSE, libPaths = libPaths, verbose = verbose) rec <- FALSE # this function is only one time through - set(pkgDT, NULL, deps(FALSE), unname(out)) + + val <- unname(out) + if (length(val) == 0) + val <- lapply(seq_len(NROW(pkgDT)), function(x) + data.table(Package = character(), which = character(), packageFullName = character())) + set(pkgDT, NULL, deps(FALSE), val) # rec <- recursiveType(whichCatRecursive) snHere <- sn(rec) diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R index ae9fdded..a905c33b 100644 --- a/tests/testthat/setup.R +++ b/tests/testthat/setup.R @@ -3,7 +3,7 @@ if (.isDevelVersion() && nchar(Sys.getenv("R_REQUIRE_RUN_ALL_TESTS")) == 0) { } verboseForDev <- 2 Require.usePak <- FALSE -Require.installPackageSys <- 2 * (isMacOSX() %in% FALSE) +Require.installPackageSys <- 2# * (isMacOSX() %in% FALSE) if (isTRUE(Require.usePak)) if (requireNamespace("pak")) From 9974afef49cdf137e7cd50c87638819821c5351d Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Thu, 1 Aug 2024 08:12:24 -0700 Subject: [PATCH 17/24] space --- R/Require-helpers.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/Require-helpers.R b/R/Require-helpers.R index 394946e8..5c4650ba 100644 --- a/R/Require-helpers.R +++ b/R/Require-helpers.R @@ -600,7 +600,7 @@ toDT <- function(...) { #' #' detachAll <- function(pkgs, dontTry = NULL, doSort = TRUE, verbose = getOption("Require.verbose")) { - messageVerbose("Detaching is fraught with many potential problems; you may have to", + messageVerbose("Detaching is fraught with many potential problems; you may have to ", "restart your session if things aren't working", verbose = verbose, verboseLevel = 2 ) From fd09429475fef4cc5d88af551cc1d682e5c32707 Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Thu, 1 Aug 2024 10:41:54 -0700 Subject: [PATCH 18/24] more --- DESCRIPTION | 4 ++-- R/Require-helpers.R | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7d4aed9d..5ecf0c02 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -15,8 +15,8 @@ Description: A single key function, 'Require' that makes rerun-tolerant URL: https://Require.predictiveecology.org, https://github.com/PredictiveEcology/Require -Date: 2024-07-31 -Version: 1.0.0.9007 +Date: 2024-08-01 +Version: 1.0.0.9008 Authors@R: c( person(given = "Eliot J B", family = "McIntire", diff --git a/R/Require-helpers.R b/R/Require-helpers.R index 5c4650ba..206bdd94 100644 --- a/R/Require-helpers.R +++ b/R/Require-helpers.R @@ -269,7 +269,7 @@ dlGitHubFile <- function(pkg, filename = "DESCRIPTION", }, by = c("Package", "Branch") ], warning = function(w) { - browser() + # browser() }) } old <- grep("filepath|destFile", colnames(pkgDT), value = TRUE)[1] @@ -1717,8 +1717,12 @@ available.packagesWithCallingHandlers <- function(repo, type, verbose = getOptio Sys.unsetenv("R_LIBCURL_SSL_REVOKE_BEST_EFFORT") }, add = TRUE) } else { - if (any(grepl("cannot open URL", warns)) && attmpt == 1) # seems to be transient esp with predictiveecology.r-universe.dev - next + if (any(grepl("cannot open URL", warns)) && attmpt == 1) { # seems to be transient esp with predictiveecology.r-universe.dev + next + } + if (urlExists("https://www.google.com")) # this means that the repository does not have the packages.RDS file, meaning it doesn't have e.g., binary packages for R 4.2 + break + setOfflineModeTRUE(verbose = verbose) if (length(otherwarns)) { warning(warns) } @@ -1726,8 +1730,7 @@ available.packagesWithCallingHandlers <- function(repo, type, verbose = getOptio } } - if (any(grepl("cannot open URL", warns))) - setOfflineModeTRUE(verbose = verbose) + out } From 1ab739b6c09393551ad335b738edae937468bdc7 Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Thu, 1 Aug 2024 11:24:13 -0700 Subject: [PATCH 19/24] skip sys for macosx --- tests/testthat/setup.R | 2 +- tests/testthat/test-04other_testthat.R | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R index a905c33b..ae9fdded 100644 --- a/tests/testthat/setup.R +++ b/tests/testthat/setup.R @@ -3,7 +3,7 @@ if (.isDevelVersion() && nchar(Sys.getenv("R_REQUIRE_RUN_ALL_TESTS")) == 0) { } verboseForDev <- 2 Require.usePak <- FALSE -Require.installPackageSys <- 2# * (isMacOSX() %in% FALSE) +Require.installPackageSys <- 2 * (isMacOSX() %in% FALSE) if (isTRUE(Require.usePak)) if (requireNamespace("pak")) diff --git a/tests/testthat/test-04other_testthat.R b/tests/testthat/test-04other_testthat.R index 4bd324ce..7ccd9d50 100644 --- a/tests/testthat/test-04other_testthat.R +++ b/tests/testthat/test-04other_testthat.R @@ -273,8 +273,7 @@ test_that("test 3", { Require::Install("LandR", repos = "predictiveecology.r-universe.dev", libPaths = dir44, standAlone = TRUE) ) - test <- testWarnsInUsePleaseChange(warns) - expect_true(test) + expect_match(warns, paste(sep = "|", .txtPleaseRestart, .txtCouldNotBeInstalled)) } From 02ffa467f546efc68ecf11f8017dcaf610304ccc Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Thu, 1 Aug 2024 12:09:33 -0700 Subject: [PATCH 20/24] mac --- tests/testthat/test-04other_testthat.R | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/testthat/test-04other_testthat.R b/tests/testthat/test-04other_testthat.R index 7ccd9d50..c3f649c6 100644 --- a/tests/testthat/test-04other_testthat.R +++ b/tests/testthat/test-04other_testthat.R @@ -183,12 +183,14 @@ test_that("test 3", { # were multiple repos; ffbase is no longer on CRAN # can't quiet this down on linux because ffbase is not binary but rest are ... # install.packages won't do both types quiet = TRUE for some reason - warns1 <- capture_warnings( - Install("ff", # verbose = 0, - repos = c(RSPM = urlForPositPACKAGES, CRAN = "https://cloud.r-project.org" - )) - ) - expect_identical(character(0), warns1) + if (!isMacOSX()) { + warns1 <- capture_warnings( + Install("ff", # verbose = 0, + repos = c(RSPM = urlForPositPACKAGES, CRAN = "https://cloud.r-project.org" + )) + ) + expect_identical(character(), warns1) + } } if (isWindows()) { @@ -273,7 +275,7 @@ test_that("test 3", { Require::Install("LandR", repos = "predictiveecology.r-universe.dev", libPaths = dir44, standAlone = TRUE) ) - expect_match(warns, paste(sep = "|", .txtPleaseRestart, .txtCouldNotBeInstalled)) + expect_match(warns, paste(sep = "|", .txtPleaseRestart, .txtCouldNotBeInstalled, .txtInstallationPkgFailed)) } From 996c240122f665b3acd9724f70d275b94ce08290 Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Thu, 1 Aug 2024 12:36:54 -0700 Subject: [PATCH 21/24] Mac Arm64 --- R/pkgDep3.R | 5 +++++ tests/testthat/setup.R | 2 ++ tests/testthat/test-06pkgDep_testthat.R | 9 ++++++--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/R/pkgDep3.R b/R/pkgDep3.R index 41a3bc9d..6a9be966 100644 --- a/R/pkgDep3.R +++ b/R/pkgDep3.R @@ -1220,6 +1220,11 @@ addDepthAndParentPkg <- function(deps, nam, .depth) { if (is(deps, "list")) { return(Map(deps = deps, nam = names(deps), addDepthAndParentPkg, .depth = .depth)) } + setDT(deps) # sometimes esp. on Mac: + # Error in `set(deps, NULL, "parentPackage", nam)`: This data.table has either + # been loaded from disk (e.g. using readRDS()/load()) or constructed manually + # (e.g. using structure()). Please run setDT() or setalloccol() on it first + # (to pre-allocate space for new columns) before assigning by reference to it. set(deps, NULL, "parentPackage", nam) deps <- rmRifInPackageCol(deps) diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R index ae9fdded..f992daa2 100644 --- a/tests/testthat/setup.R +++ b/tests/testthat/setup.R @@ -4,6 +4,7 @@ if (.isDevelVersion() && nchar(Sys.getenv("R_REQUIRE_RUN_ALL_TESTS")) == 0) { verboseForDev <- 2 Require.usePak <- FALSE Require.installPackageSys <- 2 * (isMacOSX() %in% FALSE) +Require.offlineMode <- FALSE if (isTRUE(Require.usePak)) if (requireNamespace("pak")) @@ -54,6 +55,7 @@ withr::local_options(.local_envir = teardown_env(), install.packages.check.source = "never", install.packages.compile.from.source = "never", Require.unloadNamespaces = TRUE, + Require.offlineMode = Require.offlineMode, Require.Home = "~/GitHub/Require") withr::local_envvar(.local_envir = teardown_env(), diff --git a/tests/testthat/test-06pkgDep_testthat.R b/tests/testthat/test-06pkgDep_testthat.R index 8d15c8e2..41dd3617 100644 --- a/tests/testthat/test-06pkgDep_testthat.R +++ b/tests/testthat/test-06pkgDep_testthat.R @@ -40,9 +40,12 @@ test_that("test 6", { testthat::expect_true({ all(names(b) == pkg) }) - testthat::expect_true({ - length(b[[1]]) > length(a1[[1]]) - }) + testthat::expect_contains(extractPkgName(b[[1]]), c("data.table", "digest", "fs")) + testthat::expect_contains(extractPkgName(a[[1]]), c("data.table")) + + # testthat::expect_true({ + # length(b[[1]]) > length(a1[[1]]) + # }) # bAlt <- pkgDepAlt(pkg, recursive = TRUE, purge = TRUE) # GitHub # testthat::expect_true({length(setdiff(extractPkgName(b[[1]]), extractPkgName(bAlt[[1]]))) == 0}) From c032129909cd4688063414be25c5f93aa3aaa50a Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Thu, 1 Aug 2024 14:09:25 -0700 Subject: [PATCH 22/24] update tests for MacOS fails on rhub --- R/Require2.R | 4 ++-- tests/testthat/test-01packages_testthat.R | 14 ++++++++------ tests/testthat/test-06pkgDep_testthat.R | 9 ++++++--- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/R/Require2.R b/R/Require2.R index 15538760..252aaefc 100644 --- a/R/Require2.R +++ b/R/Require2.R @@ -1872,8 +1872,8 @@ getGitHubVersionOnRepos <- function(pkgGitHub) { pkgGitHub <- dlGitHubFile(pkgGitHub) dFile <- pkgGitHub[["DESCFile"]] hasDFile <- which(!is.na(dFile)) - set(pkgGitHub, hasDFile, "VersionOnRepos", DESCRIPTIONFileVersionV(dFile)) - mayNeedPackageNameChange <- DESCRIPTIONFileOtherV(dFile, other = "Package") + set(pkgGitHub, hasDFile, "VersionOnRepos", DESCRIPTIONFileVersionV(dFile[hasDfile])) + mayNeedPackageNameChange <- DESCRIPTIONFileOtherV(dFile[hasDfile], other = "Package") alreadyCorrect <- pkgGitHub[["Package"]][hasDFile] == mayNeedPackageNameChange notAlreadyCorrect <- alreadyCorrect %in% FALSE if (any(notAlreadyCorrect)) { diff --git a/tests/testthat/test-01packages_testthat.R b/tests/testthat/test-01packages_testthat.R index 430e386c..b401d9d5 100644 --- a/tests/testthat/test-01packages_testthat.R +++ b/tests/testthat/test-01packages_testthat.R @@ -211,9 +211,10 @@ test_that("test 1", { }, error = function(x) FALSE ) - testthat::expect_true({ - isTRUE(isInstalled) - }) + expect_match(normalizePath(out, winslash = "/"), normalizePath(dir3, winslash = "/")) + # testthat::expect_true({ + # isTRUE(isInstalled) + # }) # Try github with version dir4 <- Require:::rpackageFolder(Require::tempdir2("test4")) @@ -249,9 +250,10 @@ test_that("test 1", { testthat::expect_true({ length(mess) > 0 }) - testthat::expect_true({ - sum(grepl("could not be installed", mess)) == 1 - }) + expect_match(paste(mess, collapse = " "), .txtCouldNotBeInstalled) + # testthat::expect_true({ + # sum(grepl("could not be installed", mess)) == 1 + # }) } unlink(dirname(dir3), recursive = TRUE) unlink(dirname(dir4), recursive = TRUE) diff --git a/tests/testthat/test-06pkgDep_testthat.R b/tests/testthat/test-06pkgDep_testthat.R index 41dd3617..151cb763 100644 --- a/tests/testthat/test-06pkgDep_testthat.R +++ b/tests/testthat/test-06pkgDep_testthat.R @@ -40,8 +40,11 @@ test_that("test 6", { testthat::expect_true({ all(names(b) == pkg) }) - testthat::expect_contains(extractPkgName(b[[1]]), c("data.table", "digest", "fs")) - testthat::expect_contains(extractPkgName(a[[1]]), c("data.table")) + if (!isTRUE(all(grepl("reproducible", extractPkgName(b[[1]]))))) { + # This suggests that there was no internet -- some connections are flaky -- rhub macos R-devel + testthat::expect_contains(extractPkgName(b[[1]]), c("data.table", "digest", "fs")) + testthat::expect_contains(extractPkgName(a[[1]]), c("data.table")) + } # testthat::expect_true({ # length(b[[1]]) > length(a1[[1]]) @@ -128,7 +131,7 @@ test_that("test 6", { # needs Require or else it will try from predictiveecology.r-universe.dev ... but version is too low # warnsReq <- capture_warnings(Require::Install("Require")) warns22 <- capture_warnings( - Install("PredictiveEcology/Require@simplify4 (>=0.3.1.9021)", install = "force") + Install("PredictiveEcology/Require@development (>=0.3.1.9021)", install = "force") ) # withr::local_options(warn = 2) # withr::local_options(Require.verbose = 2) From 13545fad93685926e3494b8dc68af44d888c0b81 Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Thu, 1 Aug 2024 14:26:48 -0700 Subject: [PATCH 23/24] typo --- R/Require2.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/Require2.R b/R/Require2.R index 252aaefc..6f7cc452 100644 --- a/R/Require2.R +++ b/R/Require2.R @@ -1872,8 +1872,8 @@ getGitHubVersionOnRepos <- function(pkgGitHub) { pkgGitHub <- dlGitHubFile(pkgGitHub) dFile <- pkgGitHub[["DESCFile"]] hasDFile <- which(!is.na(dFile)) - set(pkgGitHub, hasDFile, "VersionOnRepos", DESCRIPTIONFileVersionV(dFile[hasDfile])) - mayNeedPackageNameChange <- DESCRIPTIONFileOtherV(dFile[hasDfile], other = "Package") + set(pkgGitHub, hasDFile, "VersionOnRepos", DESCRIPTIONFileVersionV(dFile[hasDFile])) + mayNeedPackageNameChange <- DESCRIPTIONFileOtherV(dFile[hasDFile], other = "Package") alreadyCorrect <- pkgGitHub[["Package"]][hasDFile] == mayNeedPackageNameChange notAlreadyCorrect <- alreadyCorrect %in% FALSE if (any(notAlreadyCorrect)) { From 548b4d1770926e5527d77427bcb8391d84b76e9f Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Thu, 1 Aug 2024 15:41:58 -0700 Subject: [PATCH 24/24] getGitHubVersionOnRepos -- defensive if internet/authentication is flaky --- R/Require-helpers.R | 3 +++ R/Require2.R | 21 +++++++++++++++------ R/messages.R | 4 ++++ tests/testthat/test-01packages_testthat.R | 2 ++ 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/R/Require-helpers.R b/R/Require-helpers.R index 206bdd94..26cd8367 100644 --- a/R/Require-helpers.R +++ b/R/Require-helpers.R @@ -262,6 +262,9 @@ dlGitHubFile <- function(pkg, filename = "DESCRIPTION", ret <- if (!is(dl, "try-error")) { destFile } else { + if (!isTRUE(urlExists(unique(url)[1]))) + if (!isTRUE(urlExists("https://www.google.com"))) + setOfflineModeTRUE(verbose = verbose) NA } diff --git a/R/Require2.R b/R/Require2.R index 6f7cc452..248cc783 100644 --- a/R/Require2.R +++ b/R/Require2.R @@ -1869,15 +1869,24 @@ moveFileToCacheOrTmp <- function(pkgInstall) { getGitHubVersionOnRepos <- function(pkgGitHub) { notYet <- is.na(pkgGitHub[["VersionOnRepos"]]) if (any(notYet)) { + # if (exists("aaaa")) browser() pkgGitHub <- dlGitHubFile(pkgGitHub) dFile <- pkgGitHub[["DESCFile"]] hasDFile <- which(!is.na(dFile)) - set(pkgGitHub, hasDFile, "VersionOnRepos", DESCRIPTIONFileVersionV(dFile[hasDFile])) - mayNeedPackageNameChange <- DESCRIPTIONFileOtherV(dFile[hasDFile], other = "Package") - alreadyCorrect <- pkgGitHub[["Package"]][hasDFile] == mayNeedPackageNameChange - notAlreadyCorrect <- alreadyCorrect %in% FALSE - if (any(notAlreadyCorrect)) { - set(pkgGitHub, hasDFile[notAlreadyCorrect], "Package", mayNeedPackageNameChange[notAlreadyCorrect]) + fesLenDFile <- file.exists(pkgGitHub$DESCFile[hasDFile]) + if (any(!fesLenDFile)) { + set(pkgGitHub, hasDFile[!fesLenDFile], "DESCFile", "") + # pkgGitHub[hasDFile[!fesLenDFile], DESCFile := ""] + } + if (any(fesLenDFile)) { + set(pkgGitHub, hasDFile[fesLenDFile], "VersionOnRepos", DESCRIPTIONFileVersionV(dFile[hasDFile[fesLenDFile]])) + mayNeedPackageNameChange <- DESCRIPTIONFileOtherV(dFile[hasDFile[fesLenDFile]], other = "Package") + alreadyCorrect <- pkgGitHub[["Package"]][hasDFile[fesLenDFile]] == mayNeedPackageNameChange + notAlreadyCorrect <- alreadyCorrect %in% FALSE + if (any(notAlreadyCorrect)) { + set(pkgGitHub, hasDFile[fesLenDFile][notAlreadyCorrect], "Package", + mayNeedPackageNameChange[notAlreadyCorrect]) + } } # pkgGitHub[!is.na(DESCFile), VersionOnRepos := DESCRIPTIONFileVersionV(DESCFile)] } diff --git a/R/messages.R b/R/messages.R index 82d5e7ec..3e8826f4 100644 --- a/R/messages.R +++ b/R/messages.R @@ -373,3 +373,7 @@ paste0WithLineFeed <- function(mess, lineWidth = getOptionWidthWithBuffer()) { } getOptionWidthWithBuffer <- function(buff = 10) getOption("width") - 10 + +msgStripColor <- function(msg) { + gsub("\033\\[..{0,1}m", "", msg) +} diff --git a/tests/testthat/test-01packages_testthat.R b/tests/testthat/test-01packages_testthat.R index b401d9d5..294e0603 100644 --- a/tests/testthat/test-01packages_testthat.R +++ b/tests/testthat/test-01packages_testthat.R @@ -191,6 +191,8 @@ test_that("test 1", { ) ) + if (isTRUE(any(grepl(msgStripColor(messageCantInstallNoInternet("")), msgStripColor(warns))))) + skip("Flaky internet") inst22 <- suppressMessages( Require::Require("achubaty/fpCompare", install = "force", returnDetails = TRUE,