PredictiveEcology / Require

Simple R package to install and load packages conducive to a reproducible workflow
https://require.predictiveecology.org/
21 stars 6 forks source link

Require does not respect `.libPaths()` from within a `simInitAndSpades` call? #55

Closed CeresBarros closed 2 years ago

CeresBarros commented 2 years ago

I have used a workflow to install all necessary packages in a temporary directory, which seems to work well. However, when I run simInitAndSpades with the default options("spades.useRequire"), Require tries to reinstall all packages in a different location ‘D:/GitHub/LandR-Manual/reproducible/4.2’ and I'm not even sure where's it's getting it from...

> mySim <- simInitAndSpades(times = times,
+                           params = parameters, 
+                           modules = modules, 
+                           objects = objects, 
+                           paths = paths,
+                           outputs = outputs,
+                           debug = TRUE)
Setting:
  options(
    reproducible.cachePath = 'C:/Users/cbarros/AppData/Local/Temp/Rtmp4yDQJB/cache'
    spades.inputPath = 'C:/Users/cbarros/AppData/Local/Temp/Rtmp4yDQJB/inputs'
    spades.outputPath = 'C:/Users/cbarros/AppData/Local/Temp/Rtmp4yDQJB/outputs'
    spades.modulePath = 'C:/Users/cbarros/AppData/Local/Temp/Rtmp4yDQJB/modules'
  )
Paths set to:
  options(
    rasterTmpDir = 'C:/Users/cbarros/AppData/Local/Temp/Rtmp4yDQJB/SpaDES/scratch/raster'
    reproducible.cachePath = 'C:/Users/cbarros/AppData/Local/Temp/Rtmp4yDQJB/cache'
    spades.inputPath = 'C:/Users/cbarros/AppData/Local/Temp/Rtmp4yDQJB/inputs'
    spades.outputPath = 'C:/Users/cbarros/AppData/Local/Temp/Rtmp4yDQJB/outputs'
    spades.modulePath = 'C:/Users/cbarros/AppData/Local/Temp/Rtmp4yDQJB/modules'
    spades.scratchPath = 'C:/Users/cbarros/AppData/Local/Temp/Rtmp4yDQJB/SpaDES/scratch'
  )
  terra::terraOptions(tempdir = 'C:/Users/cbarros/AppData/Local/Temp/Rtmp4yDQJB/SpaDES/scratch/terra'
Using GITHUB_PAT to access files on GitHub
package 'Require' successfully unpacked and MD5 sums checked
Installing in groups to maintain dependencies: CircStats, DBI, MatrixModels, MuMIn, R.methodsS3, R.oo, R.utils, R6, RApiSerialize, RColorBrewer, RCurl, RSQLite, Rcpp, RcppArmadillo, RcppEigen, RcppParallel, SpaDES.core, SparseM, abind, askpass, assertthat, backports, base64enc, bit, bit64, bitops, blob, brio, broom, cachem, callr, car, carData, checkmate, classInt, cli, colorspace, corrplot, cowplot, cpp11, crayon, curl, data.table, desc, diffobj, digest, dismo, dplyr, e1071, ellipsis, evaluate, fansi, farver, fastdigest, fasterize, fastmap, fastmatch, fpCompare, fs, generics, ggplot2, ggpubr, ggrepel, ggsci, ggsignif, ggspatial, glue, gridBase, gridExtra, gtable, highr, httr, igraph, isoband, jpeg, jsonlite, knitr, labeling, lifecycle, lme4, lobstr, magrittr, maptools, memoise, mime, minqa, munsell, nloptr, numDeriv, openssl, pbkrtest, pillar, pkgconfig, pkgload, plogr, plyr, png, polynom, praise, prettymapr, prettyunits, processx, proxy, ps, purrr, qs, quantreg, quickPlot, raster, rematch2, reproducible, rgdal, rgeos, rjson, rlang, rosm, rprojroot, rstatix, s2, scales, sf, sp, stringfish, stringi, stringr, sys, terra, testthat, tibble, tidyr, tidyselect, units, utf8, vctrs, viridisLite, waldo, whisker, withr, wk, xfun, yaml, peutils, tiler, SpaDES.tools, amc, pemisc, map, LandR, LandR.CS
-- Installing from:
  -- Local: CircStats, DBI, MatrixModels, MuMIn, R.methodsS3, R.oo, R.utils, R6, RApiSerialize, RColorBrewer, RCurl, RSQLite, Rcpp, RcppArmadillo, RcppEigen, RcppParallel, SpaDES.core, SparseM, abind, askpass, assertthat, backports, base64enc, bit, bit64, bitops, blob, brio, broom, cachem, callr, car, carData, checkmate, classInt, cli, colorspace, corrplot, cowplot, cpp11, crayon, curl, data.table, desc, diffobj, digest, dismo, dplyr, e1071, ellipsis, evaluate, fansi, farver, fastdigest, fasterize, fastmap, fastmatch, fpCompare, fs, generics, ggplot2, ggpubr, ggrepel, ggsci, ggsignif, ggspatial, glue, gridBase, gridExtra, gtable, highr, httr, igraph, isoband, jpeg, jsonlite, knitr, labeling, lifecycle, lme4, lobstr, magrittr, maptools, memoise, mime, minqa, munsell, nloptr, numDeriv, openssl, pbkrtest, pillar, pkgconfig, pkgload, plogr, plyr, png, polynom, praise, prettymapr, prettyunits, processx, proxy, ps, purrr, qs, quantreg, quickPlot, raster, rematch2, reproducible, rgdal, rgeos, rjson, rlang, rosm, rprojroot, rstatix, s2, scales, sf, sp, stringfish, stringi, stringr, sys, terra, testthat, tibble, tidyr, tidyselect, units, utf8, vctrs, viridisLite, waldo, whisker, withr, wk, xfun, yaml
-- 1:141 of 149 (grp 1 of 8). Estimated time left: ...; est. finish: ...calculating
Using local cache of CircStats_0.2-6.zip, DBI_1.1.3.zip, MatrixModels_0.5-1.zip, MuMIn_1.47.1.zip, R.methodsS3_1.8.2.zip, R.oo_1.25.0.zip, R.utils_2.12.0.zip, R6_2.5.1.zip, RApiSerialize_0.1.2.zip, RColorBrewer_1.1-3.zip, RCurl_1.98-1.9.zip, RSQLite_2.2.18.zip, Rcpp_1.0.9.zip, RcppArmadillo_0.11.4.0.1.zip, RcppEigen_0.3.3.9.2.zip, RcppParallel_5.1.5.zip, SpaDES.core_1.1.0.zip, SparseM_1.81.zip, abind_1.4-5.zip, askpass_1.1.zip, assertthat_0.2.1.zip, backports_1.4.1.zip, base64enc_0.1-3.zip, bit_4.0.4.zip, bit64_4.0.5.zip, bitops_1.0-7.zip, blob_1.2.3.zip, brio_1.1.3.zip, broom_1.0.1.zip, cachem_1.0.6.zip, callr_3.7.2.zip, car_3.1-0.zip, carData_3.0-5.zip, checkmate_2.1.0.zip, classInt_0.4-8.zip, cli_3.4.1.zip, colorspace_2.0-3.zip, corrplot_0.92.zip, cowplot_1.1.1.zip, cpp11_0.4.2.zip, crayon_1.5.2.zip, curl_4.3.3.zip, data.table_1.14.2.zip, desc_1.4.2.zip, diffobj_0.3.5.zip, digest_0.6.29.zip, dismo_1.3-9.zip, dplyr_1.0.10.zip, e1071_1.7-11.zip, ellipsis_0.3.2.zip, evaluate_0.17.zip, fansi_1.0.3.zip, farver_2.1.1.zip, fastdigest_0.6-3.zip, fasterize_1.0.3.zip, fastmap_1.1.0.zip, fastmatch_1.1-3.zip, fpCompare_0.2.4.zip, fs_1.5.2.zip, generics_0.1.3.zip, ggplot2_3.3.6.zip, ggpubr_0.4.0.zip, ggrepel_0.9.1.zip, ggsci_2.9.zip, ggsignif_0.6.3.zip, ggspatial_1.1.6.zip, glue_1.6.2.zip, gridBase_0.4-7.zip, gridExtra_2.3.zip, gtable_0.3.1.zip, highr_0.9.zip, httr_1.4.4.zip, igraph_1.3.5.zip, isoband_0.2.6.zip, jpeg_0.1-9.zip, jsonlite_1.8.2.zip, knitr_1.40.zip, labeling_0.4.2.zip, lifecycle_1.0.3.zip, lme4_1.1-30.zip, lobstr_1.1.2.zip, magrittr_2.0.3.zip, maptools_1.1-4.zip, memoise_2.0.1.zip, mime_0.12.zip, minqa_1.2.4.zip, munsell_0.5.0.zip, nloptr_2.0.3.zip, numDeriv_2016.8-1.1.zip, openssl_2.0.3.zip, pbkrtest_0.5.1.zip, pillar_1.8.1.zip, pkgconfig_2.0.3.zip, pkgload_1.3.0.zip, plogr_0.2.0.zip, plyr_1.8.7.zip, png_0.1-7.zip, polynom_1.4-1.zip, praise_1.0.0.zip, prettymapr_0.2.4.zip, prettyunits_1.1.1.zip, processx_3.7.0.zip, proxy_0.4-27.zip, ps_1.7.1.zip, purrr_0.3.5.zip, qs_0.25.4.zip, quantreg_5.94.zip, quickPlot_0.1.8.zip, raster_3.6-3.zip, rematch2_2.1.2.zip, reproducible_1.2.10.zip, rgdal_1.5-32.zip, rgeos_0.5-9.zip, rjson_0.2.21.zip, rlang_1.0.6.zip, rosm_0.2.6.zip, rprojroot_2.0.3.zip, rstatix_0.7.0.zip, s2_1.1.0.zip, scales_1.2.1.zip, sf_1.0-8.zip, sp_1.5-0.zip, stringfish_0.15.7.zip, stringi_1.7.8.zip, stringr_1.4.1.zip, sys_3.4.zip, terra_1.6-17.zip, testthat_3.1.5.zip, tibble_3.1.8.zip, tidyr_1.2.1.zip, tidyselect_1.2.0.zip, units_0.8-0.zip, utf8_1.2.2.zip, vctrs_0.4.2.zip, viridisLite_0.4.1.zip, waldo_0.4.0.zip, whisker_0.4.zip, withr_2.5.0.zip, wk_0.6.0.zip, xfun_0.33.zip, yaml_2.3.5.zip
Warning: packages ‘SpaDES.core’, ‘quickPlot’, ‘reproducible’ are in use and will not be installed
Installing packages into ‘D:/GitHub/LandR-Manual/reproducible/4.2’ <--------
(as ‘lib’ is unspecified)
CeresBarros commented 2 years ago

full reprex

options(repos = c(CRAN = "https://cloud.r-project.org"))
tempDir <- tempdir()

pkgPath <- file.path(tempDir, "packages", version$platform,
                     paste0(version$major, ".", strsplit(version$minor, "[.]")[[1]][1]))
dir.create(pkgPath, recursive = TRUE)
.libPaths(pkgPath, include.site = FALSE)

if (!require(Require, lib.loc = pkgPath)) {
  install.packages("Require")
  library(Require, lib.loc = pkgPath)
}

setLinuxBinaryRepo()
Require("PredictiveEcology/SpaDES.project@6d7de6ee12fc967c7c60de44f1aa3b04e6eeb5db", 
        require = FALSE, upgrade = FALSE, standAlone = TRUE)

paths <- list(inputPath = normPath(file.path(tempDir, "inputs")), 
              cachePath = normPath(file.path(tempDir, "cache")), 
              modulePath = normPath(file.path(tempDir, "modules")), 
              outputPath = normPath(file.path(tempDir, "outputs")))

SpaDES.project::getModule(modulePath = paths$modulePath,
                          c("PredictiveEcology/Biomass_core@master"),
                          overwrite = TRUE)

## make sure all necessary packages are installed:
outs <- SpaDES.project::packagesInModules(modulePath = paths$modulePath)
Require(c(unname(unlist(outs)), "SpaDES"),
        require = FALSE, standAlone = TRUE)

## load necessary packages
Require(c("SpaDES", "LandR", "reproducible"), upgrade = FALSE, install = FALSE)          

times <- list(start = 0, end = 30)

studyArea <- Cache(randomStudyArea, size = 1e7) # cache this so it creates a random one only once on a machine

# Pick the species you want to work with – using the naming convention in "Boreal" column of LandR::sppEquivalencies_CA
speciesNameConvention <- "Boreal"
speciesToUse <- c("Pice_Gla", "Popu_Tre", "Pinu_Con")

sppEquiv <- sppEquivalencies_CA[get(speciesNameConvention) %in% speciesToUse]
# Assign a colour convention for graphics for each species
sppColorVect <- sppColors(sppEquiv, speciesNameConvention,
                          newVals = "Mixed", palette = "Set1")

## Usage example
modules <- as.list("Biomass_core")
objects <- list(studyArea = studyArea, sppEquiv = sppEquiv, sppColorVect = sppColorVect)

successionTimestep <- 10L

## keep default values for most parameters 
## (omitted from this list)
parameters <- list(
  Biomass_core = list(
    "sppEquivCol" = speciesNameConvention
    , "successionTimestep" = successionTimestep
    , ".plots" = c("screen", "object")
    , ".plotInitialTime" = times$start
    , ".plots" = c("screen", "png")
    , ".saveInitialTime" = times$start
    , ".useCache" = "init"
    , ".useParallel" = FALSE
  )
)

outputs <- data.frame(expand.grid(objectName = "cohortData",
                                  saveTime = unique(seq(times$start, times$end, by = 1)),
                                  eventPriority = 1,
                                  stringsAsFactors = FALSE))

graphics.off()

mySim <- simInitAndSpades(times = times,
                          params = parameters, 
                          modules = modules, 
                          objects = objects, 
                          paths = paths,
                          outputs = outputs,
                          debug = TRUE)
CeresBarros commented 2 years ago

🤔 I can't reproduce this anymore. something must've been screwed up during my run.