Running ‘test-all.R’ [24s/40s]
Running the tests in ‘tests/test-all.R’ failed.
Complete output:
  > library(testthat)
  > test_check("SpaDES.core")
  Loading required package: SpaDES.core
  Loading required package: quickPlot
  Loading required package: reproducible
  
  Attaching package: 'SpaDES.core'
  
  The following objects are masked from 'package:stats':
  
      end, start
  
  The following object is masked from 'package:utils':
  
      citation
  
  
   *** caught segfault ***
  address (nil), cause 'unknown'
  
  Traceback:
   1: RandomFieldsUtils::RFoptions()
   2: internal.rfoptions(xyz_notation = length(y) != 0, expected_number_simu = n,     ..., RELAX = !missing(model) && is(model, "formula"))
   3: RandomFields::RFsimulate(model, y = 1:ncSpeedup, x = 1:nrSpeedup,     grid = TRUE, ...)
   4: raster(RandomFields::RFsimulate(model, y = 1:ncSpeedup, x = 1:nrSpeedup,     grid = TRUE, ...))
   5: gaussMap(template, scale = 10, var = 0.03, speedup = speedup,     inMemory = inMemory)
   6: Init(sim)
   7: FUN(...)
   8: Cache(FUN = get(moduleCall, envir = fnEnv), sim = sim, eventTime = cur[["eventTime"]],     eventType = cur[["eventType"]], .objects = moduleSpecificObjects,     notOlderThan = notOlderThan, outputObjects = moduleSpecificOutputObjects,     classOptions = classOptions, showSimilar = showSimilar, cacheRepo = sim@paths[["cachePath"]])
   9: Cache(FUN = get(moduleCall, envir = fnEnv), sim = sim, eventTime = cur[["eventTime"]],     eventType = cur[["eventType"]], .objects = moduleSpecificObjects,     notOlderThan = notOlderThan, outputObjects = moduleSpecificOutputObjects,     classOptions = classOptions, showSimilar = showSimilar, cacheRepo = sim@paths[["cachePath"]])
  10: eval(fnCallAsExpr)
  11: eval(fnCallAsExpr)
  12: .runEvent(sim, cacheIt, debug, moduleCall, fnEnv, cur, notOlderThan,     showSimilar = showSimilar, .pkgEnv)
  13: doEvent(sim, debug = debug, notOlderThan = notOlderThan, events = events,     ...)
  14: withCallingHandlers({    recoverModeWrong <- getOption("spades.recoverMode")    if (!is.null(recoverModeWrong))         warning("Please set options('recoveryMode') with a 'y', not options('recoverMode')")    recoverMode <- getOption("spades.recoveryMode", FALSE)    clearFileBackedObjs(.pkgEnv$.sim$.recoverableObjs, recoverMode)    .pkgEnv$.sim <- NULL    .pkgEnv$.sim <- sim    oldGetPaths <- getPaths()    do.call(setPaths, append(sim@paths, list(silent = TRUE)))    on.exit({        do.call(setPaths, append(list(silent = TRUE), oldGetPaths))    }, add = TRUE)    if (!is.null(sim@.xData[["._randomSeed"]])) {        message("Resetting .Random.seed of session because sim$._randomSeed is not NULL. ",             "To get a different seed, run: sim$._randomSeed <- NULL to clear it.")        assign(".Random.seed", sim@.xData$._randomSeed[[1]],             envir = .GlobalEnv)        if (!is.null(sim$._rng.kind)) {            do.call("RNGkind", as.list(sim$._rng.kind))        }        sim@.xData[["._randomSeed"]] <- NULL        sim@.xData[["._rng.kind"]] <- NULL    }    if (is.null(sim@.xData[["._startClockTime"]]))         sim@.xData[["._startClockTime"]] <- Sys.time()    if (is.list(events)) {        unspecifiedEvents <- setdiff(unlist(modules(sim, TRUE)),             names(events))        unspecifiedEvents <- setdiff(unspecifiedEvents, "progress")        if (NROW(sim@outputs) == 0L)             unspecifiedEvents <- setdiff(unspecifiedEvents, "save")        if (NROW(sim@inputs) == 0L)             unspecifiedEvents <- setdiff(unspecifiedEvents, "load")        useChkpnt <- !any(is.na(params(sim)$checkpoint))        if (!useChkpnt)             unspecifiedEvents <- setdiff(unspecifiedEvents, "checkpoint")        if (length(unspecifiedEvents)) {            message("NOTE: ", paste(unspecifiedEvents, collapse = ", "),                 " not specified in events argument. ", "This means all events the module(s) will run. You may have intended to add e.g., list(",                 unspecifiedEvents[1], "= 'init')")        }    }    if (is.null(sim@.xData[["._knownObjects"]])) {        moduleNames <- unname(modules(sim))        names(moduleNames) <- moduleNames        sim@.xData[["._knownObjects"]] <- lapply(moduleNames,             function(x) character())        sim@.xData[["._knownObjects"]]$sim <- character()    }    if (is.null(sim@.xData[["._simRndString"]]))         sim@.xData[["._simRndString"]] <- rndstr(1, 8, characterFirst = TRUE)    .pkgEnv$searchPath <- search()    .pkgEnv[["spades.browserOnError"]] <- (interactive() & !identical(debug,         FALSE) & getOption("spades.browserOnError"))    .pkgEnv[["spades.nCompleted"]] <- getOption("spades.nCompleted")    .pkgEnv[["skipNamespacing"]] <- !getOption("spades.switchPkgNamespaces")    .pkgEnv[["spades.keepCompleted"]] <- getOption("spades.keepCompleted",         TRUE)    if (getOption("spades.memoryUseInterval", 0) > 0) {        if (requireNamespace("future", quietly = TRUE)) {            originalPlan <- future::plan()            sim <- memoryUseSetup(sim, originalPlan)            on.exit({                sim <- memoryUseOnExit(sim, originalPlan)            }, add = TRUE)        }        else {            message(futureMessage)        }    }    sim@.xData$.timeunits <- timeunits(sim)    on.exit({        if (!.pkgEnv[["skipNamespacing"]]) .modifySearchPath(.pkgEnv$searchPath,             removeOthers = TRUE)        rm(".timeunits", envir = sim@.xData)        if (isTRUE(getOption("spades.saveSimOnExit", FALSE))) {            if (!isTRUE(.pkgEnv$.cleanEnd)) {                if (recoverMode > 0) {                  sim <- recoverModeOnExit(sim, rmo, recoverMode)                }                messageInterrupt1(recoverMode)            } else {                message(crayon::magenta("simList saved in\n",                   crayon::blue("SpaDES.core:::.pkgEnv$.sim"),                   "\nIt will be deleted at next spades() call."))            }            .pkgEnv$.sim <- sim            .pkgEnv$.cleanEnd <- NULL        }        if (!is.null(sim$._restartRList)) {            sim@simtimes[["current"]] <- sim@events[[1]]$eventTime            sim$._restartRList$.spadesCall <- match.call()            restartFormals <- formals(restartR)            end(sim) <- sim$._restartRList$endOrig            restartR(sim = sim, reloadPkgs = getOption("spades.restartR.reloadPkgs",                 restartFormals$reloadPkgs), .First = getOption("spades.restartR..First",                 restartFormals$.First), .RDataFile = getOption("spades.restartR.filename",                 sim$._restartRList$simFilename), restartDir = getOption("spades.restartR.restartDir",                 restartFormals$restartDir))        }    }, add = TRUE)    if (!is.null(.plots)) {        sim@params <- updateParamSlotInAllModules(sim@params,             .plots, ".plots", needClass = "character", needValuesMess = paste0("It must be one or more of 'screen', ",                 "'object', 'raw' and any of the classes that ggplot2::ggsave ",                 "can handle, e.g., 'png'"))        if (is.null(.plotInitialTime) && !any(.plots %in% "screen"))             sim@params <- updateParamSlotInAllModules(sim@params,                 NA_integer_, ".plotInitialTime", needClass = "numeric")    }    if (!is.null(.plotInitialTime)) {        sim@params <- updateParamSlotInAllModules(sim@params,             .plotInitialTime, ".plotInitialTime", needClass = "numeric")        if (is.na(.plotInitialTime))             sim@params <- updateParamSlotInAllModules(sim@params,                 NA_character_, ".plots", needClass = "character")    }    if (!is.null(.saveInitialTime)) {        sim@params <- updateParamSlotInAllModules(sim@params,             .saveInitialTime, ".saveInitialTime", needClass = "numeric")    }    if (!is.na(progress)) {        tu <- sim@simtimes[["timeunit"]]        if (isTRUE(progress)) {            progress <- "graphical"        }        if (is.numeric(progress)) {            sim@params$.progress$interval <- (end(sim, tu) -                 start(sim, tu))/progress            progress <- "graphical"        }        if (!is.na(pmatch(progress, "graphical"))) {            sim@params$.progress$type <- "graphical"        }        else if (!is.na(pmatch(progress, "text"))) {            sim@params$.progress$type <- "text"        }        if (!is.na(sim@params$.progress$type) && is.na(sim@params$.progress$interval)) {            sim@params$.progress$interval <- NULL        }    }    if (!(all(unlist(lapply(debug, identical, FALSE))))) {        .pkgEnv[[".spadesDebugFirst"]] <- TRUE        .pkgEnv[[".spadesDebugWidth"]] <- c(9, 10, 9, 13)    }    sim@.xData[["._firstEventClockTime"]] <- Sys.time()    if (length(sim@completed)) {        existingCompleted <- sort(as.integer(ls(sim@completed,             sorted = FALSE)))        prevStart <- get(as.character(existingCompleted[1]),             envir = sim@completed)        prevEnd <- get(as.character(existingCompleted[length(existingCompleted)]),             envir = sim@completed)        if (length(.grepSysCalls(sys.calls(), "restartSpades")) ==             0)             if (start(sim, unit = attr(prevStart[["eventTime"]],                 "unit")) <= prevStart[["eventTime"]] && (time(sim,                 unit = attr(prevStart[["eventTime"]], "unit")) ==                 start(sim, unit = attr(prevStart[["eventTime"]],                   "unit"))))                 sim@completed <- new.env(parent = emptyenv())    }    if (recoverMode > 0) {        rmo <- NULL        allObjNames <- outputObjectNames(sim)        if (is.null(allObjNames))             recoverMode <- 0    }    useFuture <- getOption("spades.futureEvents", FALSE)    if (useFuture) {        if (!requireNamespace("future", quietly = TRUE))             stop("To use 'spades.futureEvents', please run \ninstall.packages('future') ")        message("useFuture is set to TRUE; this will attempt to spawn events in a separate process, ",             "if their outputs are not needed by other events. STILL EXPERIMENTAL. Use cautiously.",             "User must manage future::plan, e.g., \nfuture::plan(multiprocess(workers = 2))")        sim$.futureEventsSkipped <- 0        sim$simFuture <- list()    }    if (length(sim@events)) {        specialStart <- sim@events[[1]][["eventTime"]] < sim@simtimes[["current"]] &&             sim@simtimes[["current"]] > sim@simtimes[["end"]]        if (isTRUE(specialStart))             sim@simtimes[["current"]] <- sim@events[[1]][["eventTime"]]    }    while (sim@simtimes[["current"]] <= sim@simtimes[["end"]]) {        if (recoverMode > 0) {            rmo <- recoverModePre(sim, rmo, allObjNames, recoverMode)        }        sim <- doEvent(sim, debug = debug, notOlderThan = notOlderThan,             events = events, ...)        if (recoverMode > 0) {            rmo <- recoverModePost(sim, rmo, recoverMode)        }        if (exists("._conditionalEvents", envir = sim, inherits = FALSE)) {            condEventsToOmit <- integer()            for (condNum in seq(sim$._conditionalEvents)) {                cond <- sim$._conditionalEvents[[condNum]]                if (isTRUE(eval(cond$condition))) {                  curTime <- time(sim)                  if (curTime >= cond$minEventTime && curTime <=                     cond$maxEventTime) {                    message("  Conditional Event -- ", cond$condition,                       " is true. Scheduling for now")                    sim <- scheduleEvent(sim, eventTime = curTime,                       moduleName = cond$moduleName, eventType = cond$eventType,                       eventPriority = cond$eventPriority)                    condEventsToOmit <- c(condEventsToOmit, condNum)                  }                }            }            if (length(condEventsToOmit)) {                sim$._conditionalEvents <- sim$._conditionalEvents[-condEventsToOmit]                if (length(sim$._conditionalEvents) == 0) {                  rm("._conditionalEvents", envir = sim)                }            }        }        if (useFuture) {            if (length(sim$simFuture) > 1) {                for (simFut in seq_along(sim$simFuture)) {                  if (future::resolved(sim$simFuture[[1]][[1]])) {                    sim <- resolveFutureNow(sim, cause = paste0(modNameInFuture(sim$simFuture[1]),                       " finished running"))                  }                }            }        }    }    if (useFuture) {        if (length(sim$simFuture)) {            for (simFut in seq_along(sim$simFuture)) {                sim <- resolveFutureNow(sim, cause = "End of simulation")            }        }        message(crayon::magenta(sim$.futureEventsSkipped, " events ran while events ran in futures"))    }    sim@simtimes[["current"]] <- sim@simtimes[["end"]]    .pkgEnv$.cleanEnd <- TRUE    return(invisible(sim))}, warning = function(w) {    if (requireNamespace("logging", quietly = TRUE)) {        logging::logwarn(paste0(collapse = " ", c(names(w), w)))    }}, error = function(e) {    if (requireNamespace("logging", quietly = TRUE)) {        logging::logerror(e)    }    else {        stop(e)    }}, message = function(m) {    if (newDebugging && requireNamespace("logging", quietly = TRUE)) {        logging::loginfo(m$message)    }    if (useNormalMessaging) {        message(loggingMessage(m$message))    }    tryCatch(invokeRestart("muffleMessage"), error = function(e) NULL)})
  15: spades(Copy(mySim), notOlderThan = Sys.time(), debug = FALSE)
  16: spades(Copy(mySim), notOlderThan = Sys.time(), debug = FALSE)
  17: withCallingHandlers(code, message = function(condition) {    out$push(condition)    maybe_restart("muffleMessage")})
  18: capture_messages({    sims <- spades(Copy(mySim), notOlderThan = Sys.time(), debug = FALSE)})
  19: "loaded cached copy of init event in randomLandscapes module" %in%     capture_messages({        sims <- spades(Copy(mySim), notOlderThan = Sys.time(),             debug = FALSE)    })
  20: eval_bare(expr, quo_get_env(quo))
  21: quasi_label(enquo(object), label, arg = "object")
  22: expect_true(!"loaded cached copy of init event in randomLandscapes module" %in%     capture_messages({        sims <- spades(Copy(mySim), notOlderThan = Sys.time(),             debug = FALSE)    }))
  23: eval(code, test_env)
  24: eval(code, test_env)
  25: withCallingHandlers({    eval(code, test_env)    if (!handled && !is.null(test)) {        skip_empty()    }}, expectation = handle_expectation, skip = handle_skip, warning = handle_warning,     message = handle_message, error = handle_error)
  26: doTryCatch(return(expr), name, parentenv, handler)
  27: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  28: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  29: doTryCatch(return(expr), name, parentenv, handler)
  30: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]),     names[nh], parentenv, handlers[[nh]])
  31: tryCatchList(expr, classes, parentenv, handlers)
  32: tryCatch(withCallingHandlers({    eval(code, test_env)    if (!handled && !is.null(test)) {        skip_empty()    }}, expectation = handle_expectation, skip = handle_skip, warning = handle_warning,     message = handle_message, error = handle_error), error = handle_fatal,     skip = function(e) {    })
  33: test_code(desc, code, env = parent.frame(), reporter = reporter)
  34: test_that("test event-level cache & memory leaks", {    skip_if_not_installed("RandomFields")    testInitOut <- testInit(smcc = FALSE, opts = list(reproducible.useMemoise = FALSE))    opts <- options(reproducible.cachePath = tmpdir)    on.exit({        options(opts)        testOnExit(testInitOut)    }, add = TRUE)    modPath <- system.file("sampleModules", package = "SpaDES.core")    mods <- c("caribouMovement", "randomLandscapes", "fireSpread")    pkgs <- reqdPkgs(module = mods, modulePath = modPath)    expect_true(length(pkgs) == 3)    expect_true(all(names(pkgs) == mods))    expect_true(all(c("raster", "sp", "SpaDES.tools", "RColorBrewer") %in%         unlist(pkgs)))    mySim <- simInit(times = list(start = 0, end = 3, timeunit = "year"),         params = list(.globals = list(stackName = "landscape",             burnStats = "nPixelsBurned"), fireSpread = list(.plotInitialTime = NA),             caribouMovement = list(.plotInitialTime = NA), randomLandscapes = list(.plotInitialTime = NA,                 .useCache = "init", .showSimilar = TRUE)), modules = mods,         paths = list(modulePath = modPath, outputPath = tmpdir,             cachePath = tmpdir), outputs = data.frame(objectName = c("landscape",             "caribou"), stringsAsFactors = FALSE))    set.seed(1123)    expect_true(!"loaded cached copy of init event in randomLandscapes module" %in%         capture_messages({            sims <- spades(Copy(mySim), notOlderThan = Sys.time(),                 debug = FALSE)        }))    landscapeMaps1 <- raster::dropLayer(sims$landscape, "Fires")    fireMap1 <- sims$landscape$Fires    mess1 <- capture_messages({        sims <- spades(Copy(mySim), debug = FALSE)    })    expect_true(any(grepl(pattern = "loaded cached copy of init event in randomLandscapes module",         mess1)))    landscapeMaps2 <- raster::dropLayer(sims$landscape, "Fires")    fireMap2 <- sims$landscape$Fires    expect_equal(landscapeMaps1, landscapeMaps2)    expect_false(isTRUE(suppressWarnings(all.equal(fireMap1,         fireMap2))))    sims$crazyFunction2 <- SpaDES.core:::bindrows    end(sims) <- end(sims) + 0.1    mess <- capture.output(warnsFunction <- capture_warnings(simsOut <- spades(sims,         debug = FALSE)))    expect_true(length(warnsFunction) == 0)    sims$crazyFunction3 <- sims$.mods$caribouMovement$Init    end(sims) <- end(sims) + 0.1    simsOut <- spades(sims, debug = FALSE)    mess <- capture.output(warnsFunction <- capture_warnings(simsOut <- spades(sims,         debug = FALSE)))    expect_true(length(warnsFunction) == 0)    fn <- function() {        rnorm(1)    }    sims$crazyFunction <- fn    end(sims) <- end(sims) + 0.1    mess <- capture.output(warnsFunction <- capture_warnings(simsOut <- spades(sims,         debug = FALSE)))    expect_true(length(warnsFunction) > 0)    expect_true(grepl("function", warnsFunction))    expect_true(grepl("crazyFunction", warnsFunction))    expect_true(!grepl("crazyFormula", warnsFunction))    expect_true(!grepl("formula", warnsFunction))    sims$crazyFormula <- formula(hi ~ test)    end(sims) <- end(sims) + 0.1    mess <- capture.output(warnsFormula <- capture_warnings(simsOut <- spades(sims,         debug = FALSE)))    expect_true(length(warnsFormula) > 0)    expect_true(grepl("formula", warnsFormula))    expect_true(grepl("crazyFormula", warnsFormula))    expect_true(!grepl("crazyFunction", warnsFormula))    expect_true(!grepl("function", warnsFormula))    sims$.mods$caribouMovement$.objects$crazyFunction <- function() {        rnorm(1)    }    end(sims) <- end(sims) + 0.1    mess <- capture.output(warnsFunction <- capture_warnings(simsOut <- spades(sims,         debug = FALSE)))    expect_true(length(warnsFunction) > 0)    expect_true(grepl("function", warnsFunction))    expect_true(grepl("crazyFunction", warnsFunction))    expect_true(!grepl("crazyFormula", warnsFunction))    expect_true(grepl("mod", warnsFunction))    expect_true(!grepl("formula", warnsFunction))    sims$.mods$caribouMovement$.objects$crazyFormula <- formula(hi ~         test)    end(sims) <- end(sims) + 0.1    mess <- capture.output(warnsFormula <- capture_warnings(simsOut <- spades(sims,         debug = FALSE)))    expect_true(length(warnsFormula) > 0)    expect_true(grepl("formula", warnsFormula))    expect_true(grepl("mod", warnsFormula))    expect_true(grepl("crazyFormula", warnsFormula))    expect_true(!grepl("crazyFunction", warnsFormula))    expect_true(!grepl("function", warnsFormula))})
  35: eval(code, test_env)
  36: eval(code, test_env)
  37: withCallingHandlers({    eval(code, test_env)    if (!handled && !is.null(test)) {        skip_empty()    }}, expectation = handle_expectation, skip = handle_skip, warning = handle_warning,     message = handle_message, error = handle_error)
  38: doTryCatch(return(expr), name, parentenv, handler)
  39: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  40: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  41: doTryCatch(return(expr), name, parentenv, handler)
  42: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]),     names[nh], parentenv, handlers[[nh]])
  43: tryCatchList(expr, classes, parentenv, handlers)
  44: tryCatch(withCallingHandlers({    eval(code, test_env)    if (!handled && !is.null(test)) {        skip_empty()    }}, expectation = handle_expectation, skip = handle_skip, warning = handle_warning,     message = handle_message, error = handle_error), error = handle_fatal,     skip = function(e) {    })
  45: test_code(NULL, exprs, env)
  46: source_file(path, child_env(env), wrap = wrap)
  47: FUN(X[[i]], ...)
  48: lapply(test_paths, test_one_file, env = env, wrap = wrap)
  49: doTryCatch(return(expr), name, parentenv, handler)
  50: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  51: tryCatchList(expr, classes, parentenv, handlers)
  52: tryCatch(code, testthat_abort_reporter = function(cnd) {    cat(conditionMessage(cnd), "\n")    NULL})
  53: with_reporter(reporters$multi, lapply(test_paths, test_one_file,     env = env, wrap = wrap))
  54: test_files(test_dir = test_dir, test_package = test_package,     test_paths = test_paths, load_helpers = load_helpers, reporter = reporter,     env = env, stop_on_failure = stop_on_failure, stop_on_warning = stop_on_warning,     wrap = wrap, load_package = load_package)
  55: test_files(test_dir = path, test_paths = test_paths, test_package = package,     reporter = reporter, load_helpers = load_helpers, env = env,     stop_on_failure = stop_on_failure, stop_on_warning = stop_on_warning,     wrap = wrap, load_package = load_package, parallel = parallel)
  56: test_dir("testthat", package = package, reporter = reporter,     ..., load_package = "installed")
  57: test_check("SpaDES.core")
  An irrecoverable exception occurred. R is aborting now ...