Code Monkey home page Code Monkey logo

spades.project's Introduction

CRAN_Status_Badge Downloads R build status

SpaDES.project

Quickly setup 'SpaDES' project directories, get modules, and deal with a number of issues related to reproducibility and reusabililty. This package was designed with a PERFICT approach in mind (See McIntire et al. 2022).

Why Choose This Package

Achieving PERFICT in your projects can be challenging, but it becomes more accessible with the use of SpaDES. The SpaDES.project tool is designed to streamline the setup of SpaDES projects. Complementing the R scripting language, there are three valuable tools at your disposal:

  1. Integrated Development Environment (IDE): This IDE encourages the organization of your work into projects, enhancing your workflow efficiency.
  2. Modular Coding Approach: Embrace a modular approach to coding, allowing for easier maintenance and collaboration.
  3. Version Control (Optional): For those interested in code development, SpaDES supports version control through platforms like GitHub, giving you control over project history and collaboration.

Our Recommended Tools

Our preferred toolset includes Posit (specifically, RStudio), SpaDES, and GitHub. While these are our recommendations, there are alternative options available. We acknowledge that not all users are familiar with Git, and that's perfectly acceptable. SpaDES.project has been designed to cater to all users, whether they choose to use a Git-controlled project or not.

Project Challenges

Beyond these tools, our extensive experience in managing projects with diverse developers, operating systems, users, data sources, and packages has revealed various challenges. These challenges arise due to the nature of open, modular, and interoperable projects. As project complexity increases, typical reproducible workflows may falter. Issues include:

  • Variations in .Rprofile files.
  • Non-transferable file paths.
  • Incompatibilities between packages on different operating systems.
  • Conflicts between package versions.
  • Problems with the order of package loading and installation (e.g., inability to install a different version of a package while it's already loaded).
  • Spaghetti code, where objects are defined in one file and used in another.
  • Differences in users' familiarity with GitHub.
  • The presence of cryptic code and objects ("just run that line, don't worry about what it does").
  • Objects defined by a user lingering in the .GlobalEnv, leading to undetected issues.
  • Varying competencies among different users.

Given these complexities, it's not enough to create a "reproducible" script; it must be a "reusable" script that functions flawlessly on any machine, operating system, and for any user.

Users can certainly attempt to address these issues individually, but we've developed SpaDES.project as a solution. It's derived from our most intricate projects to date, yet it's designed with beginners in mind. We've anticipated these challenges so that users won't encounter them unexpectedly during their project journeys.

Getting Started

See this package readme and vignettes to get started.

  1. Getting started vignette
  2. Using git and GitHub
  3. Installing R
  4. Finding other SpaDES modules

Website: https://SpaDES.PredictiveEcology.org

Wiki: https://github.com/PredictiveEcology/SpaDES/wiki

Installation

Current stable release

R build status Codecov test coverage

Install from CRAN:

# Not yet on CRAN
# install.packages("SpaDES.project")

Development version (unstable)

R build status Codecov test coverage

install.packages("SpaDES.project", repos = c("predictiveecology.r-universe.dev", getOption("repos")))

Get modules in a new project

setupProject(paths = list(projectPath = tempdir()),
             modules = c("PredictiveEcology/Biomass_borealDataPrep@development",
                         "PredictiveEcology/Biomass_core@development"))

More examples

The following example provides all that is necessary to run all modules, in a very short set of commands, from (almost) any starting condition. We tend to use this approach is many of our projects.

Key features:

  1. The project is fully self contained in a folder, with packages being installed to a unique library based on the projectPath.
  2. No use of install.packages without an if
  3. No library or require calls before any package installations.
  4. All functions are "rerun-capable", meaning they do not "redo" the action when rerun if the action is not necessary. e.g., remotes::install_github does not reinstall the package if the SHA has not changed.
  5. No assigning of objects into the .GlobalEnv. If projects are small/simple, using the .GlobalEnv is OK. As a project gets larger, unexpected behaviours arise because objects can be erroneaously found in the .GlobalEnv if they have a common name, like out, when functions should instead fail.
  6. Minimum packages installed prior to setupProject. After SpaDES.project and Require updates are on CRAN, this will be further simplified.
  7. Minimal use of setwd, to allow user's to easily change it (including comment it out) with simple search image.

It is fully contained as a separate project, separate libraries, which means it doesn't do what it did for me at the start... package collisions. I used a setwd("~"), which is the bare minimum ... you can tell a user to change that to a place where this project will live.

getOrUpdatePkg <- function(p, minVer = "0") {
  if (!isFALSE(try(packageVersion(p) < minVer, silent = TRUE) )) {
    repo <- c("predictiveecology.r-universe.dev", getOption("repos"))
    install.packages(p, repos = repo)
  }
}

getOrUpdatePkg("remotes")
remotes::install_github("PredictiveEcology/Require", ref = "bda9fa50003981880c06287fea1db9272b62912c", upgrade = FALSE)# getOrUpdatePkg("reproducible", "2.0.9")
getOrUpdatePkg("SpaDES.project", "0.0.8.9040")

setwd("~")
out <- SpaDES.project::setupProject(
  runName = "Example",
  paths = list(projectPath = "integratingSpaDESmodules",
               modulePath = "SpaDES_Modules",
               outputPath = file.path("outputs", runName)),
  modules = c("tati-micheletti/speciesAbundance@main",
              "tati-micheletti/temperature@main",
              "tati-micheletti/speciesAbundTempLM@main"),
  times = list(start = 2013,
               end = 2032),
  updateRprofile = TRUE,
  Restart = TRUE
)

snippsim <- do.call(SpaDES.core::simInitAndSpades, out)

See Getting Started Vignette

Contributions

Please see CONTRIBUTING.md for information on how to contribute to this project.

spades.project's People

Contributors

achubaty avatar ceresbarros avatar eliotmcintire avatar ianmseddy avatar tati-micheletti avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

spades.project's Issues

`tools::file_ext(modules)` returns "R" not ".R"

Found a bug in setupModules using SpaDES.project@transition

repos <- c("predictiveecology.r-universe.dev", getOption("repos"))
install.packages("remotes", repos = repos)
remotes::install_github("PredictiveEcology/Require", ref = "a2c60495228e3a73fa513435290e84854ca51907", upgrade = FALSE)
Require::Require("PredictiveEcology/SpaDES.project@transition")

debugonce(setupModules)

setupModules(name = "castorExample",
             paths = list("projectPath" = "."),
             modules = "bcgov/castor@main/R/SpaDES-modules/dataCastor/dataCastor.R",
             inProject = TRUE)

Browse[2]> modules
[1] "bcgov/castor@main/R/SpaDES-modules/dataCastor/dataCastor.R"
debug: exts <- tools::file_ext(modules)
Browse[2]> exts
[1] "R"
Browse[2]> debug: isRepo <- nzchar(exts) & exts %in% ".R"
[1] FALSE

`parseFileLists` can't find `defineModule()`/`defineParameter()` but they are there?

Require::Require("CeresBarros/SpaDES.project@52-toolsfile_extmodules-returns-r-not-r-")
debug(setupModules)
setupModules(name = "castorExample",
             paths = list("projectPath" = "."),
             modules = "bcgov/castor@main/R/SpaDES-modules/dataCastor/dataCastor.R", 
             inProject = TRUE)

Browse[1]>       modules <- parseFileLists(modules, paths, namedList = FALSE, overwrite = isTRUE(overwrite),
+                                 envir = envirCur, verbose = verbose)
./R/SpaDES-modules/dataCastor/dataCastor.R already exists; not downloading
                                                              url     is localFile
                                                           <char> <char>    <char>
1: bcgov/castor@main/R/SpaDES-modules/.../dataCastor/dataCastor.R   --->          
Error in defineModule(sim, list(name = "dataCastor", description = NA,  :   could not find function "defineModule"
Error in defineParameter(".useCache", "logical", FALSE, NA, NA, "Should this entire module be run with caching activated? This is generally intended for data-type modules, where stochasticity and time are not relevant") :   could not find function "defineParameter"
Error in bind_rows(expectsInput(objectName = "scenario", objectClass = "data.table",  :   could not find function "bind_rows"
Error in bind_rows(createsOutput("zone.length", objectClass = "integer",  :   could not find function "bind_rows"

However, a dive into shows:

Browse[2]> pp[[1]]
defineModule(sim, list(name = "dataCastor", description = NA, 
    keywords = NA, authors = c(person("Kyle", "Lochhead", email = "[email protected]", 
        role = c("aut", "cre")), person("Tyler", "Muhly", email = "[email protected]", 
        role = c("aut", "cre"))), childModules = character(0), 
    version = list(SpaDES.core = "0.2.5", dataCastor = "0.0.1"), 
    spatialExtent = raster::extent(rep(NA_real_, 4)), timeframe = as.POSIXlt(c(NA, 
        NA)), timeunit = "year", citation = list("citation.bib"), 
    documentation = list("README.txt", "dataCastor.Rmd"), reqdPkgs = list("sf", 
        "rpostgis", "DBI", "RSQLite", "data.table", "rpostgis", 
        "sqldf"), parameters = rbind(defineParameter(".useCache", 
        "logical", FALSE, NA, NA, "Should this entire module be run with caching activated? This is generally intended for data-type modules, where stochasticity and time are not relevant"), 
        defineParameter("startTime", "numeric", start(sim), NA, 
            NA, desc = "Simulation time at which to start"), 
        defineParameter("endTime", "numeric", end(sim), NA, NA, 
            desc = "Simulation time at which to end"), defineParameter("seedRandomLandscape", 
            "integer", 123, 1, 1e+05, "The seed for building random landscapes"), 
        defineParameter("maxAgeRandomLandscape", "integer", 250, 
            1, 400, "The maximum age for building random landscapes"), 
        defineParameter("dbName", "character", "postgres", NA, 
        (...)

So the function is there, as are many defineParameters.

Not sure how to fix this, or I'd propose a solution...

Object missing from output of `setupProject`: partial matching issue?

The studyArea object is missing from out in the following example. I wonder if this is related to studyArea being a partial match to studyAreaLarge

Require::Require("PredictiveEcology/SpaDES.project@windowsTesting")

inputPath <- "D:/GitHub/LandR-tutorials/LandRDemo_coreVeg/inputs"

## it seems `params =`is evaluated first so all of these need to be defined here.
sppEquivCol <- "Boreal"
vegLeadingProportion <- 0
successionTimestep <- 10L
eventCaching <- c(".inputObjects", "init")
useParallel <- FALSE
simTimes <- list(start = 2001, end = 2031)

out <- setupProject(name = "LandRDemo_coreVeg",
                    options = list(
                      "reproducible.destinationPath" = inputPath
                      , "reproducible.useCache" = TRUE
                      , "reproducible.useNewDigestAlgorithm" = 2
                      , "reproducible.useTerra" = TRUE
                      , "spades.moduleCodeChecks" = TRUE
                      , "spades.inputPath" = inputPath
                    ),
                    paths = list(
                      projectPath = "D:/GitHub/LandR-tutorials/LandRDemo_coreVeg"
                      , modulePath = "D:/GitHub/LandR-tutorials/LandRDemo_coreVeg/modules"
                      , inputPath = inputPath
                      , scratchPath = tempdir()
                      , packagePath = "D:/GitHub/LandR-tutorials/packages"
                    ),
                    modules = c(
                      "PredictiveEcology/Biomass_speciesData@terra-migration"
                      , "PredictiveEcology/Biomass_borealDataPrep@terra-migration"
                      , "PredictiveEcology/Biomass_speciesParameters@development"
                      , "PredictiveEcology/Biomass_core@terra-migration"
                      , "PredictiveEcology/Biomass_validationKNN@development"
                    ),
                    ##
                    ## NECESSARY OBJECTS -----------------------------------
                    ## STUDY AREA(S)
                    studyAreaLarge = {
                      originalcrs <- "+proj=longlat +datum=NAD83 +no_defs +ellps=GRS80 +towgs84=0,0,0"
                      Biomass_corecrs <- "+proj=lcc +lat_1=49 +lat_2=77 +lat_0=0 +lon_0=-95 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0"

                      largeExtent <- c(xmin = -104.757, xmax = -104.2197, ymin = 55.68663, ymax = 56.20319)
                      studyAreaL <- terra::vect(terra::ext(largeExtent))
                      studyAreaL <-  terra::vect(terra::geom(studyAreaL), "polygons", crs = originalcrs, atts = data.frame(id = 1:length(studyAreaL)))
                      studyAreaL <- terra::project(studyAreaL, Biomass_corecrs)
                      studyAreaL
                    },
                    studyArea = {
                      originalcrs <- "+proj=longlat +datum=NAD83 +no_defs +ellps=GRS80 +towgs84=0,0,0"
                      Biomass_corecrs <- "+proj=lcc +lat_1=49 +lat_2=77 +lat_0=0 +lon_0=-95 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0"

                      smallExtent <- c(xmin = -104.757, xmax = -104.48835, ymin = 55.68663, ymax = 55.94491)
                      studyAreaS <- terra::vect(terra::ext(smallExtent))
                      studyAreaS <-  terra::vect(terra::geom(studyAreaS), "polygons", crs = originalcrs, atts = data.frame(id = 1:length(studyAreaS)))
                      studyAreaS <- terra::project(studyAreaS, Biomass_corecrs)
                      studyAreaS
                    },
                    ##
                    ## SPECIES LISTS
                    sppEquiv = {
                      data("sppEquivalencies_CA", package = "LandR")
                      sppEquivalencies_CA[grep("Pin", LandR), `:=`(EN_generic_short = "Pine",
                                                                   EN_generic_full = "Pine",
                                                                   Leading = "Pine leading")]
                      sppEquivalencies_CA[grep("Betu_pap", LandR), `:=`(EN_generic_short = "Birch",
                                                                        EN_generic_full = "Birch",
                                                                        Leading = "Birch leading")]
                      ## all Popu will be merged
                      sppEquivalencies_CA[grep("Popu_", LandR), `:=`(EN_generic_short = "Poplar",
                                                                     EN_generic_full = "Poplar",
                                                                     Leading = "Poplar leading")]
                      sppEquivalencies_CA[grep("Popu_", LandR), Boreal := "Popu_Spp"]

                      ## define spp column to use for model
                      # sppEquivCol <- "Boreal"
                      sppEquivalencies_CA <- sppEquivalencies_CA[!"", on = sppEquivCol]
                      sppEquivalencies_CA <- na.omit(sppEquivalencies_CA, sppEquivCol)
                      sppEquivalencies_CA
                    },
                    sppColorVect = {
                      LandR::sppColors(sppEquiv, sppEquivCol, newVals = "Mixed", palette = "Accent")
                    },
                    speciesParams = {
                      list(
                        "shadetolerance" = list(
                          Betu_Pap = 1
                          , Lari_Lar = 1
                          , Pice_Gla = 2
                          , Pice_Mar = 3
                          , Pinu_Ban = 1.5
                          , Popu_Spp = 1
                        )
                      )
                    },
                    ##
                    ## SIMULATION SETUP ------------------------------------
                    times = simTimes,
                    params = source("params.R")
)

names(out)

simOut <- do.call(SpaDES.core::simInitAndSpades, out) ## fails due to missing studyArea

`setupSideEffects` and `setupOptions` have the same description

The description of these two functions in SpaDES.project@transition seems to be identical. It is not clear how they differ. An example for each would also be useful, as I'm unsure whether I understand how to create "user-desidered" options vs the generic options via options(...)

setupSideEffects can handle sequentially specified values, meaning a user can first create a list of default options, then a list of user-desired options that may or may not replace individual values. This can create hierarchies, based on order.

setupOptions can handle sequentially specified values, meaning a user can first create a list of default options, then a list of user-desired options that may or may not replace individual values. This can create hierarchies, based on order.

store previous libPaths in the object output by setupProject()

for us as developers, this would be very useful for project setup/teardown in tests and examples.

we could simply out <- setupProject(); .teardownProject(out) and have libPaths reset, instead of (currently) requiring out$paths and origLibPaths to be passed to .teardownProject().

rename package

Although the templates are currently geared towards workflows for projects using SpaDES, I think this package is more general than SpaDES per se. Since the templated workflows are about implementing a PERFICT workflow (and not SpaDES), perhaps we should rename the package.

Suggestions:

  • perfict

Thoughts? @eliotmcintire @CeresBarros @tati-micheletti

2 different `data.table`-related errors

I hit two separate data.table errors when running the example below.
Please note that I am trying to create the project from scratch. This is, I opened a clean RStudio session, outside of any project and am using setupProject to create the project folder structure and import modules.

Require::Require(c("PredictiveEcology/LandR@development",
                   "CeresBarros/SpaDES.project@misc-fixes",
                   "terra"))

out <- setupProject(name = "LandRDemo_vegOnly",
                    options = list("reproducible.useTerra" = TRUE),
                    paths = list(projectPath = "D:/GitHub/LandR-tutorials/LandRDemo_coreVeg",
                                 modulePath = "D:/GitHub/LandR-tutorials/LandRDemo_coreVeg/modules",
                                 scratchPath = tempdir(),
                                 packagePath = "D:/GitHub/LandR-tutorials/packages"),
                    modules = c("PredictiveEcology/Biomass_speciesData@terra-migration",
                                "PredictiveEcology/Biomass_borealDataPrep@terra-migration",
                                "PredictiveEcology/Biomass_speciesParameters@development",
                                "PredictiveEcology/Biomass_core@terra-migration",
                                "PredictiveEcology/Biomass_validationKNN@development")
)

The first error was happened during the internal getModule call, on line 115 (rbindlist failed)

Item 2 has 10 columns, inconsistent with item 1 which has 11 columns. To fill missing columns use fill=TRUE

When I tried running again to debug(getModule) I got:

setting up paths ...
Setting:
  options(
    reproducible.cachePath = 'D:/GitHub/LandR-tutorials/LandRDemo_coreVeg/cache'
    spades.inputPath = 'D:/GitHub/LandR-tutorials/LandRDemo_coreVeg/inputs'
    spades.outputPath = 'D:/GitHub/LandR-tutorials/LandRDemo_coreVeg/outputs'
    spades.modulePath = 'D:/GitHub/LandR-tutorials/LandRDemo_coreVeg/modules'
    spades.scratchPath = 'C:/Users/cbarros/AppData/Local/Temp/Rtmp04wFjH'
  )
  done setting up paths
Error in packageVersion(dai, lib.loc = .libPaths()[1]) : 
  there is no package called ‘data.table’

implement delayed start for sims to mitigate file race conditions

Rather than having to set this up at the project level, it'd be nice to specify a delayed start (e.g., using Sys.sleep()) when running simulations.

This is useful when starting multiple concurrent simulations which all access the same raster layers or other files.

setupProject is not finding the url although it can be opened in the browser

Reprex:

> library("SpaDES.project")
> .nodes <- 2
> out <- setupProject(.mode = .mode,
+                     .nodes = .nodes,
+                     options = "PredictiveEcology/SpaDES.project@transition/inst/options.R"
+ )
setting up paths ...
Setting:
  options(
    reproducible.cachePath = '/home/tmichele/projects/borealBirdsAndForestry/cache'
    spades.inputPath = '/home/tmichele/projects/borealBirdsAndForestry/inputs'
    spades.outputPath = '/home/tmichele/projects/borealBirdsAndForestry/outputs'
    spades.modulePath = '/home/tmichele/projects/borealBirdsAndForestry/modules'
    spades.scratchPath = '/tmp/RtmpqeebqI/borealBirdsAndForestry'
  )
  done setting up paths
Copying SpaDES.project, data.table, Require, rprojroot packages to paths$packagePath (/home/tmichele/.local/share/R/borealBirdsAndForestry/packages/x86_64-pc-linux-gnu/4.3)
  no packages to set up
.libPaths() are: /home/tmichele/.local/share/R/borealBirdsAndForestry/packages/x86_64-pc-linux-gnu/4.3, /usr/lib/R/library
setting up options...
Using GITHUB_PAT to access files on GitHub
Error in download.file(URL, destfile = destfile, quiet = TRUE) :
  cannot open URL 'https://raw.githubusercontent.com//PredictiveEcology/SpaDES.project/transition/inst/options.R'
  ... Did not download inst/options.R
Error in file(filename, "r") : cannot open the connection
In addition: Warning message:
In file(filename, "r") :
  cannot open file '/home/tmichele/projects/borealBirdsAndForestry/inst/options.R': No such file or directory
>

don't use package subdir within the project dir?

Because Rstudio a) actively monitors all files withn the project directory for changes, and b) insists on searching the packages subdir when trying to do quick find of files (e.g., using Ctrl + .), there are performance issues when a large number of packages are being used with a project.

WORKAROUND:
Use a project-specific package directory, but place it outside the project directory.

How do packrat/renv avoid this?

See: rstudio/rstudio#1984

The main project is not being set up properly as a git repo when using `useGit="Sub"`.

The main project is not being set up properly as a git repo when using useGit="Sub". A minimal REPREX:

getOrUpdatePkg <- function(p, minVer, repo) {
  if (!isFALSE(try(packageVersion(p) < minVer, silent = TRUE) )) {
    if (missing(repo)) repo = c("predictiveecology.r-universe.dev", getOption("repos"))
    install.packages(p, repos = repo)
  }
}

getOrUpdatePkg("Require", "0.3.1.14")
getOrUpdatePkg("SpaDES.project", "0.0.8.9012")
getOrUpdatePkg("SpaDES.core", "2.0.2.9006") # development

runName <- "Test_Repo"

out <- SpaDES.project::setupProject(
  name = runName,
  paths = list(projectPath = file.path(getwd(), runName),
               modulePath = "modules"
  ),
  modules = # Passing just one module to simulate the submodule's creation
    file.path("PredictiveEcology",
              c(paste0(# terra-migration
                c("Biomass_speciesData"),
                "@terra-migration")
              )),
  useGit = "Sub"
)

`setupProject(..., Restart = TRUE)` creates RStudio project, but `setupProject(..., Restart = FALSE)` doesn't

The code below creates an RStudio project file and .Rproj.user folder, in addtion to restarting RStudio.

Require::Require("PredictiveEcology/SpaDES.project@windowsTesting")
out <- setupProject(name = "LandRDemo_coreVeg",
                    options = list("reproducible.useTerra" = TRUE),
                    paths = list(projectPath = "D:/GitHub/LandR-tutorials/LandRDemo_coreVeg",
                                 modulePath = "D:/GitHub/LandR-tutorials/LandRDemo_coreVeg/modules",
                                 scratchPath = tempdir(),
                                 packagePath = "D:/GitHub/LandR-tutorials/packages"),
                    modules = c("PredictiveEcology/Biomass_speciesData@terra-migration",
                                "PredictiveEcology/Biomass_borealDataPrep@terra-migration",
                                "PredictiveEcology/Biomass_speciesParameters@development",
                                "PredictiveEcology/Biomass_core@terra-migration",
                                "PredictiveEcology/Biomass_validationKNN@development"),
                   Restart = TRUE
)

When, Restart = FALSE, however the RStudio project file and .Rproj.user folder are not created. Is this intended?

I'm thinking it may be good to create the RStudio project file and .Rproj.user even if not restarting (i.e. when Restart = FALSE), as a user may want to use the code above in a "discardable" script to initiate the project and then open the project directly from RStudio at a later date.

`getModule` errors when module exists

getModule is erroring with the module already exists in modulePath. This happens when the existing module version/branch is the same or different.
The error is probably happening when the repo and local versions are compared?

devtools::load_all()  ## using tip of 'Require2' branch
modPath <- file.path(tempdir(), "modules")
moduleNameAndBranch <- c("PredictiveEcology/Biomass_core@development (>= 1.3.9)")
getModule(moduleNameAndBranch, modulePath = modPath, overwrite = TRUE)

# trying URL 'https://github.com/PredictiveEcology/Biomass_core/archive/master.zip'
# downloaded 2.6 MB
# 
# PredictiveEcology/Biomass_core@master downloaded and placed in C:/Users/cbarros/AppData/Local/Temp/Rtmpqits0B/modules/Biomass_core
# $`PredictiveEcology/Biomass_core@master`
# [1] "C:/Users/cbarros/AppData/Local/Temp/Rtmpqits0B/modules/Biomass_core"

## now try again 
getModule(moduleNameAndBranch, modulePath = modPath, overwrite = TRUE)
# Error in verOnline[[gr$repo]] : invalid subscript type 'list'

## delete module
unlink(dir(modPath, full.names = TRUE), recursive = TRUE)

## now try again 
getModule(moduleNameAndBranch, modulePath = modPath, overwrite = TRUE)
# trying URL 'https://github.com/PredictiveEcology/Biomass_core/archive/master.zip'
# downloaded 2.6 MB
# 
# PredictiveEcology/Biomass_core@master downloaded and placed in C:/Users/cbarros/AppData/Local/Temp/Rtmpqits0B/modules/Biomass_core
# $`PredictiveEcology/Biomass_core@master`
# [1] "C:/Users/cbarros/AppData/Local/Temp/Rtmpqits0B/modules/Biomass_core"

## delete module
unlink(dir(modPath, full.names = TRUE), recursive = TRUE)

## get a different version
moduleNameAndBranch <- c("PredictiveEcology/Biomass_core@master")
getModule(moduleNameAndBranch, modulePath = modPath, overwrite = TRUE)
# trying URL 'https://github.com/PredictiveEcology/Biomass_core/archive/master.zip'
# downloaded 2.6 MB
# 
# PredictiveEcology/Biomass_core@master downloaded and placed in C:/Users/cbarros/AppData/Local/Temp/Rtmpqits0B/modules/Biomass_core
# $`PredictiveEcology/Biomass_core@master`
# [1] "C:/Users/cbarros/AppData/Local/Temp/Rtmpqits0B/modules/Biomass_core"

## try first one
moduleNameAndBranch <- c("PredictiveEcology/Biomass_core@development (>= 1.3.9)")
getModule(moduleNameAndBranch, modulePath = modPath, overwrite = TRUE)
# Error in verOnline[[gr$repo]] : invalid subscript type 'list'

`setupProject(..., sideEffects)` documentation seems circular and may ned more detail

With SpaDES.project@windowsTesting

The documentation for the sideEffects argument reads:

Optional. This can be an expression or one or more filenames or a code chunk surrounded by {...}. This/these will be parsed and evaluated, but nothing returned. This is intended to be used for functions, such as cloud authentication or configurations, that are run for their side effects only. See [setup](http://127.0.0.1:18919/help/library/SpaDES.project/help/setup).

This is missing information about the fact that the user can provide a "path" for a fiel hosted on GitHub, that setuProject will download if not available. when adding this information, it will be important to explain that the path is not a URL-like path as in, e.g., "https://raw.githubusercontent.com/PredictiveEcology/Biomass_speciesParameters/main/data/CHECKSUMS.txt", but rather a path formatted as "/@//" or "//" (so "PredictiveEcology/Biomass_speciesParameters@master/data/CHECKSUMS.txt")

I've also noticed that clicking on setup takes me to the same help page.

`setupProject` examples have an error?

In using SpaDES.project@49100296b6f4515e7f3a594ee374025ecec095d6 (presently the head of windowsTesting) the examples for setupProject seem to have an error:

image

checking absolute paths

With fs already being used, we should use fs::is_absolute_path() within isAbsolutePath() (which seems to only add names to the returned logical vector). fs is better tested/supported and will catch more edge cases than we can using basic regex matching.

allow user to disable gitignore update

currently, setupProject() is overwriting .gitignore, interfering with git submodules and .Rprofile. (we should revisit the decision to ignore .Rprofile)

`getModule` no longer assumes modules come from PredictiveEcology, when account name is not specified

This used to work a few months ago when getModule was still part of SpaDES.install.

Note that it tries to download a master.zip and extract from a development.zip?

I have the feeling the "version" number could be the culprit, since the download of "CeresBarros/Biomass_speciesFactorial@B_coreParams" works fine.

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

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

if (!"remotes" %in% installed.packages()) {
  install.packages("remotes")
}

if (!"Require" %in% installed.packages() ||
    packageVersion("Require") < "0.1.2") {
  remotes::install_github("PredictiveEcology/Require@development", upgrade = FALSE, force = TRUE)
}
## use binary linux packages if on Ubuntu
Require::setLinuxBinaryRepo()

Require::Require(c("PredictiveEcology/SpaDES.project@transition", "SpaDES.core"),
                 upgrade = FALSE, standAlone = TRUE)

SpaDES.core::setPaths(modulePath = "modules/",
                      inputPath = "inputs/",
                      outputPath = "outputs/",
                      cachePath = "cache/")
simPaths <- getPaths()

SpaDES.project::getModule("CeresBarros/Biomass_speciesFactorial@B_coreParams",
                          modulePath = simPaths$modulePath
                          , overwrite = TRUE
)

SpaDES.project::getModule("Biomass_core@development (>= 1.3.9)",
                          modulePath = simPaths$modulePath
                          , overwrite = TRUE
)

trying URL 'http://github.com/Biomass_core/development/archive/master.zip'
$`Biomass_core@development (>= 1.3.9)`
[1] "D:/GitHub/LandR_theoSppCurves/modules/development"

Warning messages:
1: In unzip(zipFileName, exdir = modulePath) :
  error 1 in extracting from zip file
2: In (function (gitRep, overwriteInner)  :
  The zipfile: D:/GitHub/LandR_theoSppCurves/modules/development.zip failed to unzip for unknown causes

list.files(simPaths$modulePath)
[1] "Biomass_speciesFactorial"

improve documentation

Working with projects:

  • why projects? background/philosophy -- PERFICT (Mcintier et al. 2022)
  • walk thorugh a complete workflow
  • new vignette: adding tests

confusing message setting up params - SpaDES.core is installed

setting up params...
Skipping checking of parameters supplied against module parameters because SpaDES.core is not installed. Please install if this check is desired.

but the package is installed:

> packageVersion("SpaDES.core")
[1] ‘1.1.1
> needPkgs <- list(
+   reproducible =  "PredictiveEcology/reproducible@development (>= 1.2.16.9017)",
+   SpaDES.core = "PredictiveEcology/SpaDES.core@development (>= 1.1.1)",
+   SpaDES.project = "PredictiveEcology/SpaDES.project@23-gitignore (>= 0.0.7.9021)"
+ )
> 
> ## WORKAROUND SpaDES.project failures to install packages correctly
> while (!require("Require", quietly = TRUE)) {
+   ## will install latest development version from PE r-universe
+   install.packages("Require", lib = pkgDir)
+   require("Require", lib.loc = pkgDir)
+ }
> 
> while (!require("SpaDES.core", quietly = TRUE)) {
+   Require::Install(needPkgs$SpaDES.core)
+ }
> ## END WORKAROUND
> 
> while (!require("SpaDES.project", quietly = TRUE)) {
>   ## TODO: PE r-universe tracks development; need diff branch
+   # install.packages("SpaDES.project", repos = "https://predictiveecology.r-universe.dev")
+   # require(SpaDES.project)
+ 
+   Require::Install(needPkgs$SpaDES.project)
+ }
> 
> out <- SpaDES.project::setupProject(
+   paths = list(projectPath = prjDir,
+                packagePath = pkgDir,
+                modulePath = "modules",
+                inputPath = "inputs",
+                outputPath = "outputs"),
+   packages = c(
+     "PredictiveEcology/CBMutils@development (>= 0.0.7.9009)", ## TODO: this should be pulled in via modules already
+     "googledrive",
+     "PredictiveEcology/Require@development (>= 0.2.6)",
+     "rgdal", "sf", ## TODO: why is Require trying to install binary versions?? not using RSPM!
+     needPkgs$SpaDES.core
+   ),
+   require = c(
+     needPkgs$reproducible,
+     needPkgs$SpaDES.core
+   ),
+   modules = c("PredictiveEcology/CBM_defaults@main",
+               "PredictiveEcology/CBM_dataPrep_SK@development",
+               "PredictiveEcology/CBM_vol2biomass@CBM_vol2biomass_SK",
+               "PredictiveEcology/CBM_core@main"),
+   params = list(
+     CBM_defaults = list(
+       .useCache = TRUE
+     ),
+     CBM_dataPrep_SK = list(
+       .useCache = TRUE
+     ),
+     CBM_vol2biomass = list(
+       outputFigurePath = switch(.user,
+                                 achubaty = file.path("outputs", "figures", "CBM_vol2biomass"),
+                                 NA), ## NA means use default: './modules/CBM_vol2biomass/figures/'
+       .useCache = TRUE
+     ),
+     CBM_core = list(
+       #.useCache = "init", #c(".inputObjects", "init")
+       .plotInterval = 1,
+       .plotInitialTime = 1990,
+       poolsToPlot = c("totalCarbon"),
+       spinupDebug = FALSE ## TODO: temporary
+     )
+   ),
+   options = list(
+     reproducible.destinationPath = if (.user == "cboisven") NULL else "inputs", ## TODO: SpaDES.project#24
+     reproducible.useTerra = TRUE
+   ),
+   times = list(start = 1990.00, end = 1993.00),
+   setLinuxBinaryRepo = FALSE, ## TODO: interferes with other package installation
+   updateRprofile  = FALSE ## TODO: verify what it is doing
+ )
setting up paths ...
Setting:
  options(
    reproducible.cachePath = '/home/achubaty/Documents/GitHub/spadesCBM/cache'
    spades.inputPath = '/mnt/projects/CBM/spadesCBM/inputs'
    spades.outputPath = '/mnt/projects/CBM/spadesCBM/outputs'
    spades.modulePath = '/home/achubaty/Documents/GitHub/spadesCBM/modules'
    spades.scratchPath = '/tmp/Rtmp3SCBUF/SpaDES.project/spadesCBM'
  )
  done setting up paths
setting up options...
The following options have been changed
                     optionName newValue oldValue
1: reproducible.destinationPath   inputs         
2:        reproducible.useTerra     TRUE    FALSE
setting up modules
                                                modules    downloaded                                        modulePath
1:                  PredictiveEcology/CBM_defaults@main already local /home/achubaty/Documents/GitHub/spadesCBM/modules
2:        PredictiveEcology/CBM_dataPrep_SK@development already local /home/achubaty/Documents/GitHub/spadesCBM/modules
3: PredictiveEcology/CBM_vol2biomass@CBM_vol2biomass_SK already local /home/achubaty/Documents/GitHub/spadesCBM/modules
4:                      PredictiveEcology/CBM_core@main already local /home/achubaty/Documents/GitHub/spadesCBM/modules
setting up packages...
Installing any missing reqdPkgs Done!
  done setting up packages
.libPaths() are: /home/achubaty/.local/share/R/spadesCBM/packages/x86_64-pc-linux-gnu/4.2, /usr/lib/R/library
setting up params...
Skipping checking of parameters supplied against module parameters because SpaDES.core is not installed. Please install if this check is desired.
  done setting up params
Option 'SpaDES.project.updateGitIgnore' is FALSE. No changes were made to .gitignore.

Pkg installation issues

I'm running into issues (or at least strange behaviour) with pkg installation using setupProject. Two things happen depending on whether setupProject is run once, or a second time. Likely both are related to using a custom packagePath that does not contain the version-specific folder.

Running a first time with an empty packagePath, leads to some packages being installed outside of the package library "version folder".

When running a second time I get an error that is likely related to me not passing a version folder to my packagePath -- this didn't use to be necessary.

reprex:

Require::Require("PredictiveEcology/SpaDES.project@transition (HEAD)")

baseDir <- "~/"

if (SpaDES.project::user("cbarros")) {
  baseDir <- "D:/GitHub/"
}

if (SpaDES.project::user("CBARROS")) {
  baseDir <- "~/GitHub/"
}

## add your own user's baseDir here if different from $HOME.
## to verify your user's name run: SpaDES.project::user()

## make sure pkg path is empty
unlink("../packages/", recursive = TRUE)

out <- setupProject(
  ## NECESSARY OBJECTS -----------------------------------
  ## these need to be evaluated first and are thus listed before any formalArg
  sppEquivCol = "Boreal",
  vegLeadingProportion = 0,
  successionTimestep = 10L,
  eventCaching = c(".inputObjects", "init"),
  useParallel = FALSE,
  name = "LandRDemo_coreVeg",
  paths = list(
    projectPath = normalizePath(file.path(baseDir, "LandR-tutorials/LandRDemo_coreVeg"), winslash = "/")
    , packagePath = "../packages"  ## relative to projectPath
  ),
  packages = c(
    # "PredictiveEcology/reproducible@development (HEAD)"
    # "PredictiveEcology/SpaDES.core@development (HEAD)",
    "PredictiveEcology/SpaDES.experiment@development (HEAD)"
  ),
  options = list(
    "reproducible.destinationPath" = paths$inputPath   ## gets paths$inputPath from argument above
    , "reproducible.useCache" = TRUE
    , "reproducible.useNewDigestAlgorithm" = 2
    , "reproducible.useTerra" = TRUE
    , "spades.moduleCodeChecks" = TRUE
    , "spades.inputPath" = paths$inputPath
    , "spades.useRequire" = FALSE
  ),
  modules = c(
    "PredictiveEcology/Biomass_speciesData@terra-migration"
    , "CeresBarros/Biomass_borealDataPrep@allowRTMLfromsim"
    , "PredictiveEcology/Biomass_speciesParameters@development"
    , "PredictiveEcology/Biomass_core@terra-migration"
    , "PredictiveEcology/Biomass_validationKNN@development"
  ),
  # Restart = TRUE, ## restart RStudio from project
  ##
  ## STUDY AREA(S)
  studyAreaLarge = {
    originalcrs <- "+proj=longlat +datum=NAD83 +no_defs +ellps=GRS80 +towgs84=0,0,0"
    Biomass_corecrs <- "+proj=lcc +lat_1=49 +lat_2=77 +lat_0=0 +lon_0=-95 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0"

    largeExtent <- c(xmin = -104.757, xmax = -104.2197, ymin = 55.68663, ymax = 56.20319)
    studyAreaL <- terra::vect(terra::ext(largeExtent))
    studyAreaL <-  terra::vect(terra::geom(studyAreaL), "polygons", crs = originalcrs, atts = data.frame(id = 1:length(studyAreaL)))
    studyAreaL <- terra::project(studyAreaL, Biomass_corecrs)
    studyAreaL
  },
  studyArea = {
    originalcrs <- "+proj=longlat +datum=NAD83 +no_defs +ellps=GRS80 +towgs84=0,0,0"
    Biomass_corecrs <- "+proj=lcc +lat_1=49 +lat_2=77 +lat_0=0 +lon_0=-95 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0"

    smallExtent <- c(xmin = -104.757, xmax = -104.48835, ymin = 55.68663, ymax = 55.94491)
    studyAreaS <- terra::vect(terra::ext(smallExtent))
    studyAreaS <-  terra::vect(terra::geom(studyAreaS), "polygons", crs = originalcrs, atts = data.frame(id = 1:length(studyAreaS)))
    studyAreaS <- terra::project(studyAreaS, Biomass_corecrs)
    studyAreaS
  },
  ##
  ## SPECIES LISTS
  sppEquiv = {
    data("sppEquivalencies_CA", package = "LandR")
    sppEquivalencies_CA[grep("Pin", LandR), `:=`(EN_generic_short = "Pine",
                                                 EN_generic_full = "Pine",
                                                 Leading = "Pine leading")]
    sppEquivalencies_CA[grep("Betu_pap", LandR), `:=`(EN_generic_short = "Birch",
                                                      EN_generic_full = "Birch",
                                                      Leading = "Birch leading")]
    ## all Popu will be merged
    sppEquivalencies_CA[grep("Popu_", LandR), `:=`(EN_generic_short = "Poplar",
                                                   EN_generic_full = "Poplar",
                                                   Leading = "Poplar leading")]
    sppEquivalencies_CA[grep("Popu_", LandR), Boreal := "Popu_Spp"]

    ## define spp column to use for model
    # sppEquivCol <- "Boreal"
    sppEquivalencies_CA <- sppEquivalencies_CA[!"", on = sppEquivCol]
    sppEquivalencies_CA <- na.omit(sppEquivalencies_CA, sppEquivCol)
    sppEquivalencies_CA
  },
  sppColorVect = {
    LandR::sppColors(sppEquiv, sppEquivCol, newVals = "Mixed", palette = "Accent")
  },
  speciesParams = {
    list(
      "shadetolerance" = list(
        Betu_Pap = 1
        , Lari_Lar = 1
        , Pice_Gla = 2
        , Pice_Mar = 3
        , Pinu_Ban = 1.5
        , Popu_Spp = 1
      )
    )
  },
  ##
  ## SIMULATION SETUP ------------------------------------
  times = list(start = 2001, end = 2031),
  params = c("CeresBarros/LandR-tutorials@main/LandRDemo_coreVeg/params.R")
)
## runs fine but see:
> list.dirs("../packages", recursive = FALSE)
[1] "../packages/4.3"            "../packages/data.table"     "../packages/fs"            
[4] "../packages/Require"        "../packages/rprojroot"      "../packages/rstudioapi"    
[7] "../packages/SpaDES.project"

running the above again (without an R session refresh):

> out <- setupProject(
+   ## NECESSARY OBJECTS -----------------------------------
+   ## these need to be evaluated first and are thus listed before any formalArg
+   sppEquivCol = "Boreal",
+   vegLeadingProportion = 0,
+   successionTimestep = 10L,
+   eventCaching = c(".inputObjects", "init"),
+   useParallel = FALSE,
+   name = "LandRDemo_coreVeg",
+   paths = list(
+     projectPath = normalizePath(file.path(baseDir, "LandR-tutorials/LandRDemo_coreVeg"), winslash = "/")
+     , packagePath = "../packages"  ## relative to projectPath
+   ),
+   packages = c(
+     # "PredictiveEcology/reproducible@development (HEAD)"
+     # "PredictiveEcology/SpaDES.core@development (HEAD)",
+     "PredictiveEcology/SpaDES.experiment@development (HEAD)"
+   ),
+   options = list(
+     "reproducible.destinationPath" = paths$inputPath   ## gets paths$inputPath from argument above
+     , "reproducible.useCache" = TRUE
+     , "reproducible.useNewDigestAlgorithm" = 2
+     , "reproducible.useTerra" = TRUE
+     , "spades.moduleCodeChecks" = TRUE
+     , "spades.inputPath" = paths$inputPath
+     , "spades.useRequire" = FALSE
+   ),
+   modules = c(
+     "PredictiveEcology/Biomass_speciesData@terra-migration"
+     , "CeresBarros/Biomass_borealDataPrep@allowRTMLfromsim"
+     , "PredictiveEcology/Biomass_speciesParameters@development"
+     , "PredictiveEcology/Biomass_core@terra-migration"
+     , "PredictiveEcology/Biomass_validationKNN@development"
+   ),
+   # Restart = TRUE, ## restart RStudio from project
+   ##
+   ## STUDY AREA(S)
+   studyAreaLarge = {
+     originalcrs <- "+proj=longlat +datum=NAD83 +no_defs +ellps=GRS80 +towgs84=0,0,0"
+     Biomass_corecrs <- "+proj=lcc +lat_1=49 +lat_2=77 +lat_0=0 +lon_0=-95 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0"
+ 
+     largeExtent <- c(xmin = -104.757, xmax = -104.2197, ymin = 55.68663, ymax = 56.20319)
+     studyAreaL <- terra::vect(terra::ext(largeExtent))
+     studyAreaL <-  terra::vect(terra::geom(studyAreaL), "polygons", crs = originalcrs, atts = data.frame(id = 1:length(studyAreaL)))
+     studyAreaL <- terra::project(studyAreaL, Biomass_corecrs)
+     studyAreaL
+   },
+   studyArea = {
+     originalcrs <- "+proj=longlat +datum=NAD83 +no_defs +ellps=GRS80 +towgs84=0,0,0"
+     Biomass_corecrs <- "+proj=lcc +lat_1=49 +lat_2=77 +lat_0=0 +lon_0=-95 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0"
+ 
+     smallExtent <- c(xmin = -104.757, xmax = -104.48835, ymin = 55.68663, ymax = 55.94491)
+     studyAreaS <- terra::vect(terra::ext(smallExtent))
+     studyAreaS <-  terra::vect(terra::geom(studyAreaS), "polygons", crs = originalcrs, atts = data.frame(id = 1:length(studyAreaS)))
+     studyAreaS <- terra::project(studyAreaS, Biomass_corecrs)
+     studyAreaS
+   },
+   ##
+   ## SPECIES LISTS
+   sppEquiv = {
+     data("sppEquivalencies_CA", package = "LandR")
+     sppEquivalencies_CA[grep("Pin", LandR), `:=`(EN_generic_short = "Pine",
+                                                  EN_generic_full = "Pine",
+                                                  Leading = "Pine leading")]
+     sppEquivalencies_CA[grep("Betu_pap", LandR), `:=`(EN_generic_short = "Birch",
+                                                       EN_generic_full = "Birch",
+                                                       Leading = "Birch leading")]
+     ## all Popu will be merged
+     sppEquivalencies_CA[grep("Popu_", LandR), `:=`(EN_generic_short = "Poplar",
+                                                    EN_generic_full = "Poplar",
+                                                    Leading = "Poplar leading")]
+     sppEquivalencies_CA[grep("Popu_", LandR), Boreal := "Popu_Spp"]
+ 
+     ## define spp column to use for model
+     # sppEquivCol <- "Boreal"
+     sppEquivalencies_CA <- sppEquivalencies_CA[!"", on = sppEquivCol]
+     sppEquivalencies_CA <- na.omit(sppEquivalencies_CA, sppEquivCol)
+     sppEquivalencies_CA
+   },
+   sppColorVect = {
+     LandR::sppColors(sppEquiv, sppEquivCol, newVals = "Mixed", palette = "Accent")
+   },
+   speciesParams = {
+     list(
+       "shadetolerance" = list(
+         Betu_Pap = 1
+         , Lari_Lar = 1
+         , Pice_Gla = 2
+         , Pice_Mar = 3
+         , Pinu_Ban = 1.5
+         , Popu_Spp = 1
+       )
+     )
+   },
+   ##
+   ## SIMULATION SETUP ------------------------------------
+   times = list(start = 2001, end = 2031),
+   params = c("CeresBarros/LandR-tutorials@main/LandRDemo_coreVeg/params.R")
+ )
setting up options...
  done setting up options
setting up paths ...
Error: invalid version specification ‘NA’

## but this looks good
> .libPaths()
[1] "C:/Users/cbarros/GitHub/LandR-tutorials/packages/4.3"     
[2] "C:/Users/cbarros/AppData/Local/Programs/R/R-4.3.1/library"

`setupModule` with GitHub .R file - errors are misleading and module ends up in "wrong place"

Require::Require("CeresBarros/SpaDES.project@52-toolsfile_extmodules-returns-r-not-r-")

list.files(".")
# [1] "castorExample.Rproj" "global.R"

setupModules(name = "castorExample",
             paths = list("modulePath" = "modules/",
                          "projectPath" = "."),
             modules = "bcgov/castor@main/R/SpaDES-modules/dataCastor/dataCastor.R", 
             inProject = TRUE)
# setting up modules...
# modules arg supplied as file(s); parsing ... 
# downloaded R/SpaDES-modules/dataCastor/dataCastor.R
# url     is localFile
# <char> <char>    <char>
#   1: bcgov/castor@main/R/SpaDES-modules/.../dataCastor/dataCastor.R   --->          
#   Error in h(simpleError(msg, call)) :   error in evaluating the argument 'sim' in selecting a method for function 'defineModule': object 'sim' not found
# object 'sim' not found
# Error in bind_rows(expectsInput(objectName = "scenario", objectClass = "data.table",  :   could not find function "bind_rows"
#                                 Error in bind_rows(createsOutput("zone.length", objectClass = "integer",  :   could not find function "bind_rows"
#                                                                  Error in endsWith(pkgs[!nas], ")") : non-character object(s)
#                                                                  

list.files(".")
# [1] "castorExample.Rproj" "global.R"            "R" 
list.files(".", recursive = TRUE)
# [1] "castorExample.Rproj"                      "global.R"                                
# [3] "R/SpaDES-modules/dataCastor/dataCastor.R"

strange output/behaviour when `setupProject(..., verbose = 2)`

Running the example below resulted in the following output:

setting up paths ...
(...)
setting up packages...
(...)
setting up options...
setting up params...
Only returning params that are relevant for modules supplied.
Omitting parameters supplied for: value, visible
 --- (set verbose == 2 to see details) --- 
  done setting up params

So I added verbose = 2 to he setupProject call bellow. Only, when I did do, I saw an error-like output and not a more verbose messaging of parameter-related operations:

setting up paths ...
Setting:
  options(
    reproducible.cachePath = 'D:/GitHub/LandR-tutorials/LandRDemo_coreVeg/cache'
    spades.inputPath = 'D:/GitHub/LandR-tutorials/LandRDemo_coreVeg/inputs'
    spades.outputPath = 'D:/GitHub/LandR-tutorials/LandRDemo_coreVeg/outputs'
    spades.modulePath = 'D:/GitHub/LandR-tutorials/LandRDemo_coreVeg/modules'
    spades.scratchPath = 'C:/Users/cbarros/AppData/Local/Temp/Rtmp8WSKuS'
  )
  done setting up paths
Copying SpaDES.project packages to paths$packagePath (D:/GitHub/LandR-tutorials/packages/4.3)
setting up modules
(...)
setting up packages...
Installing any missing reqdPkgs
Using GITHUB_PAT to access files on GitHub
Skipping install of CeresBarros/LandR@deprecatedArgs, the SHA1 has not changed from last install
-- Installing from:
  -- Local: SpaDES.project
-- 1 of 1. Estimated time left: ...; est. finish: ...calculating
Warning: package ‘SpaDES.project’ is in use and will not be installed
Error in attr(out, "Require") <- pkgDT[] : 
  attempt to set an attribute on NULL
Error in grep(value = TRUE, pattern = deets, mp) : 
  invalid regular expression 'Error in attr(out, "Require") <- pkgDT[] : 
  attempt to set an attribute on NULL
', reason 'Missing ']''
In addition: Warning message:
In grep(value = TRUE, pattern = deets, mp) :
  TRE pattern compilation error 'Missing ']''

Example:

Require::Require("PredictiveEcology/SpaDES.project@windowsTesting")
inputPath <- "D:/GitHub/LandR-tutorials/LandRDemo_coreVeg/inputs"

## it seems `params =`is evaluated first so all of these need to be defined here.
sppEquivCol <- "Boreal"
vegLeadingProportion <- 0
successionTimestep <- 10L
eventCaching <- c(".inputObjects", "init")
useParallel <- FALSE
simTimes <- list(start = 2001, end = 2031)

out <- setupProject(name = "LandRDemo_coreVeg",
                    options = list(
                      "reproducible.destinationPath" = inputPath
                      , "reproducible.useCache" = TRUE
                      , "reproducible.useNewDigestAlgorithm" = 2
                      , "reproducible.useTerra" = TRUE
                      , "spades.moduleCodeChecks" = TRUE
                      , "spades.inputPath" = inputPath
                    ),
                    paths = list(
                      projectPath = "D:/GitHub/LandR-tutorials/LandRDemo_coreVeg"
                      , modulePath = "D:/GitHub/LandR-tutorials/LandRDemo_coreVeg/modules"
                      , inputPath = inputPath
                      , scratchPath = tempdir()
                      , packagePath = "D:/GitHub/LandR-tutorials/packages"
                    ),
                    modules = c(
                      "PredictiveEcology/Biomass_speciesData@terra-migration"
                      , "PredictiveEcology/Biomass_borealDataPrep@terra-migration"
                      , "PredictiveEcology/Biomass_speciesParameters@development"
                      , "PredictiveEcology/Biomass_core@terra-migration"
                      , "PredictiveEcology/Biomass_validationKNN@development"
                    ),
                    ##
                    ## NECESSARY OBJECTS -----------------------------------
                    ## STUDY AREA(S)
                    studyAreaLarge = {
                      originalcrs <- "+proj=longlat +datum=NAD83 +no_defs +ellps=GRS80 +towgs84=0,0,0"
                      Biomass_corecrs <- "+proj=lcc +lat_1=49 +lat_2=77 +lat_0=0 +lon_0=-95 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0"

                      largeExtent <- c(xmin = -104.757, xmax = -104.2197, ymin = 55.68663, ymax = 56.20319)
                      studyAreaL <- terra::vect(terra::ext(largeExtent))
                      studyAreaL <-  terra::vect(terra::geom(studyAreaL), "polygons", crs = originalcrs, atts = data.frame(id = 1:length(studyAreaL)))
                      studyAreaL <- terra::project(studyAreaL, Biomass_corecrs)
                      studyAreaL
                    },
                    studyArea = {
                      originalcrs <- "+proj=longlat +datum=NAD83 +no_defs +ellps=GRS80 +towgs84=0,0,0"
                      Biomass_corecrs <- "+proj=lcc +lat_1=49 +lat_2=77 +lat_0=0 +lon_0=-95 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0"

                      smallExtent <- c(xmin = -104.757, xmax = -104.48835, ymin = 55.68663, ymax = 55.94491)
                      studyAreaS <- terra::vect(terra::ext(smallExtent))
                      studyAreaS <-  terra::vect(terra::geom(studyAreaS), "polygons", crs = originalcrs, atts = data.frame(id = 1:length(studyAreaS)))
                      studyAreaS <- terra::project(studyAreaS, Biomass_corecrs)
                      studyAreaS
                    },
                    ##
                    ## SPECIES LISTS
                    sppEquiv = {
                      data("sppEquivalencies_CA", package = "LandR")
                      sppEquivalencies_CA[grep("Pin", LandR), `:=`(EN_generic_short = "Pine",
                                                                   EN_generic_full = "Pine",
                                                                   Leading = "Pine leading")]
                      sppEquivalencies_CA[grep("Betu_pap", LandR), `:=`(EN_generic_short = "Birch",
                                                                        EN_generic_full = "Birch",
                                                                        Leading = "Birch leading")]
                      ## all Popu will be merged
                      sppEquivalencies_CA[grep("Popu_", LandR), `:=`(EN_generic_short = "Poplar",
                                                                     EN_generic_full = "Poplar",
                                                                     Leading = "Poplar leading")]
                      sppEquivalencies_CA[grep("Popu_", LandR), Boreal := "Popu_Spp"]

                      ## define spp column to use for model
                      # sppEquivCol <- "Boreal"
                      sppEquivalencies_CA <- sppEquivalencies_CA[!"", on = sppEquivCol]
                      sppEquivalencies_CA <- na.omit(sppEquivalencies_CA, sppEquivCol)
                      sppEquivalencies_CA
                    },
                    sppColorVect = {
                      LandR::sppColors(sppEquiv, sppEquivCol, newVals = "Mixed", palette = "Accent")
                    },
                    speciesParams = {
                      list(
                        "shadetolerance" = list(
                          Betu_Pap = 1
                          , Lari_Lar = 1
                          , Pice_Gla = 2
                          , Pice_Mar = 3
                          , Pinu_Ban = 1.5
                          , Popu_Spp = 1
                        )
                      )
                    },
                    ##
                    ## SIMULATION SETUP ------------------------------------
                    times = simTimes,
                    params = source("params.R"),
                    # verbose = 2
)

`Error in (function (nam) : argument "valObjName" is missing, with no default`

something's messed up the setupProject call is failing with an error

Require::Require("PredictiveEcology/SpaDES.project@transition (HEAD)")

baseDir <- "~/"

if (SpaDES.project::user("cbarros")) {
  baseDir <- "D:/GitHub/"
}

if (SpaDES.project::user("CBARROS")) {
  baseDir <- "~/GitHub/"
}

## add your own user's baseDir here if different from $HOME.
## to verify your user's name run: SpaDES.project::user()

out <- setupProject(
  ## NECESSARY OBJECTS -----------------------------------
  ## these need to be evaluated first and are thus listed before any formalArg
  sppEquivCol = "Boreal",
  vegLeadingProportion = 0,
  successionTimestep = 10L,
  eventCaching = c(".inputObjects", "init"),
  useParallel = FALSE,
  simTimes = list(start = 2001, end = 2031),
  name = "LandRDemo_coreVeg",
  paths = list(
    projectPath = normalizePath(file.path(baseDir, "LandR-tutorials/LandRDemo_coreVeg"), winslash = "/")
    , packagePath = "../packages"  ## relative to projectPath
  ),
  # packages = c("PredictiveEcology/SpaDES.core@development (HEAD)"),
  options = list(
    "reproducible.destinationPath" = paths$inputPath   ## gets paths$inputPath from argument above
    , "reproducible.useCache" = TRUE
    , "reproducible.useNewDigestAlgorithm" = 2
    , "reproducible.useTerra" = TRUE
    , "spades.moduleCodeChecks" = TRUE
    , "spades.inputPath" = paths$inputPath
  ),
  modules = c(
    "PredictiveEcology/Biomass_speciesData@terra-migration"
    , "PredictiveEcology/Biomass_borealDataPrep@terra-migration"
    , "PredictiveEcology/Biomass_speciesParameters@development"
    , "PredictiveEcology/Biomass_core@terra-migration"
    , "PredictiveEcology/Biomass_validationKNN@development"
  ),
  # Restart = TRUE, ## restart RStudio from project
  ##
  ## STUDY AREA(S)
  studyAreaLarge = {
    originalcrs <- "+proj=longlat +datum=NAD83 +no_defs +ellps=GRS80 +towgs84=0,0,0"
    Biomass_corecrs <- "+proj=lcc +lat_1=49 +lat_2=77 +lat_0=0 +lon_0=-95 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0"

    largeExtent <- c(xmin = -104.757, xmax = -104.2197, ymin = 55.68663, ymax = 56.20319)
    studyAreaL <- terra::vect(terra::ext(largeExtent))
    studyAreaL <-  terra::vect(terra::geom(studyAreaL), "polygons", crs = originalcrs, atts = data.frame(id = 1:length(studyAreaL)))
    studyAreaL <- terra::project(studyAreaL, Biomass_corecrs)
    studyAreaL
  },
  studyArea = {
    originalcrs <- "+proj=longlat +datum=NAD83 +no_defs +ellps=GRS80 +towgs84=0,0,0"
    Biomass_corecrs <- "+proj=lcc +lat_1=49 +lat_2=77 +lat_0=0 +lon_0=-95 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0"

    smallExtent <- c(xmin = -104.757, xmax = -104.48835, ymin = 55.68663, ymax = 55.94491)
    studyAreaS <- terra::vect(terra::ext(smallExtent))
    studyAreaS <-  terra::vect(terra::geom(studyAreaS), "polygons", crs = originalcrs, atts = data.frame(id = 1:length(studyAreaS)))
    studyAreaS <- terra::project(studyAreaS, Biomass_corecrs)
    studyAreaS
  },
  ##
  ## SPECIES LISTS
  sppEquiv = {
    data("sppEquivalencies_CA", package = "LandR")
    sppEquivalencies_CA[grep("Pin", LandR), `:=`(EN_generic_short = "Pine",
                                                 EN_generic_full = "Pine",
                                                 Leading = "Pine leading")]
    sppEquivalencies_CA[grep("Betu_pap", LandR), `:=`(EN_generic_short = "Birch",
                                                      EN_generic_full = "Birch",
                                                      Leading = "Birch leading")]
    ## all Popu will be merged
    sppEquivalencies_CA[grep("Popu_", LandR), `:=`(EN_generic_short = "Poplar",
                                                   EN_generic_full = "Poplar",
                                                   Leading = "Poplar leading")]
    sppEquivalencies_CA[grep("Popu_", LandR), Boreal := "Popu_Spp"]

    ## define spp column to use for model
    # sppEquivCol <- "Boreal"
    sppEquivalencies_CA <- sppEquivalencies_CA[!"", on = sppEquivCol]
    sppEquivalencies_CA <- na.omit(sppEquivalencies_CA, sppEquivCol)
    sppEquivalencies_CA
  },
  sppColorVect = {
    LandR::sppColors(sppEquiv, sppEquivCol, newVals = "Mixed", palette = "Accent")
  },
  speciesParams = {
    list(
      "shadetolerance" = list(
        Betu_Pap = 1
        , Lari_Lar = 1
        , Pice_Gla = 2
        , Pice_Mar = 3
        , Pinu_Ban = 1.5
        , Popu_Spp = 1
      )
    )
  },
  ##
  ## SIMULATION SETUP ------------------------------------
  times = simTimes,
  params = c("CeresBarros/LandR-tutorials@main/LandRDemo_coreVeg/params.R")
)

traceback

> traceback()
11: assign(valObjName, val2, envir = env)
10: (function (nam) 
    {
        val2[[nam]] <<- evalSUB(val2[[nam]], valObjName = valObjName, 
            envir = env, envir2 = envir)
        assign(valObjName, val2, envir = env)
    })(nam = dots[[1L]][[1L]])
9: mapply(FUN = f, ..., SIMPLIFY = FALSE)
8: Map(nam = names(val2), function(nam) {
       val2[[nam]] <<- evalSUB(val2[[nam]], valObjName = valObjName, 
           envir = env, envir2 = envir)
       assign(valObjName, val2, envir = env)
   })
7: evalSUB(d, envir = localEnv)
6: (function (d, nam) 
   {
       d1 <- evalSUB(d, envir = localEnv)
       if (is(d1, "try-error")) {
           if (isTRUE(haveDefaults)) 
               d1 <- defaultDots[[nam]]
           else d1 <- d
       }
       assign(nam, d1, envir = localEnv)
       d1
   })(d = dots[[1L]][[6L]], nam = dots[[2L]][[6L]])
5: mapply(FUN = f, ..., SIMPLIFY = FALSE)
4: Map(d = dots, nam = names(dots), function(d, nam) {
       d1 <- evalSUB(d, envir = localEnv)
       if (is(d1, "try-error")) {
           if (isTRUE(haveDefaults)) 
               d1 <- defaultDots[[nam]]
           else d1 <- d
       }
       assign(nam, d1, envir = localEnv)
       d1
   })
3: dotsToHere(dots, dotsSUB, defaultDots, envir = envir)
2: dotsToHereOuter(dots, dotsSUB, defaultDots)
1: setupProject(sppEquivCol = "Boreal", vegLeadingProportion = 0, 
       successionTimestep = 10L, eventCaching = c(".inputObjects", 
           "init"), useParallel = FALSE, simTimes = list(start = 2001, 
           end = 2031), name = "LandRDemo_coreVeg", paths = list(projectPath = normalizePath(file.path(baseDir, 
           "LandR-tutorials/LandRDemo_coreVeg"), winslash = "/"), 
           packagePath = "../packages"), options = list(reproducible.destinationPath = paths$inputPath, 
           reproducible.useCache = TRUE, reproducible.useNewDigestAlgorithm = 2, 
           reproducible.useTerra = TRUE, spades.moduleCodeChecks = TRUE, 
           spades.inputPath = paths$inputPath), modules = c("PredictiveEcology/Biomass_speciesData@terra-migration", 
           "PredictiveEcology/Biomass_borealDataPrep@terra-migration", 
           "PredictiveEcology/Biomass_speciesParameters@development", 
           "PredictiveEcology/Biomass_core@terra-migration", "PredictiveEcology/Biomass_validationKNN@development"), 
       studyAreaLarge = {
           originalcrs <- "+proj=longlat +datum=NAD83 +no_defs +ellps=GRS80 +towgs84=0,0,0"
           Biomass_corecrs <- "+proj=lcc +lat_1=49 +lat_2=77 +lat_0=0 +lon_0=-95 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0"
           largeExtent <- c(xmin = -104.757, xmax = -104.2197, ymin = 55.68663, 
               ymax = 56.20319)
           studyAreaL <- terra::vect(terra::ext(largeExtent))
           studyAreaL <- terra::vect(terra::geom(studyAreaL), "polygons", 
               crs = originalcrs, atts = data.frame(id = 1:length(studyAreaL)))
    ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.