Instantiate a specific number of agents per patch. The user can either supply a table of how many to initiate in each patch, linked by a column in that table called pops.

specificNumPerPatch(patches, numPerPatchTable = NULL, numPerPatchMap = NULL)



RasterLayer of patches, with some sort of a patch id.


A data.frame or data.table with a column named pops that matches the patches patch ids, and a second column with population size in each patch.


A RasterLayer exactly the same as patches but with agent numbers rather than ids as the cell values per patch.


A raster with 0s and 1s, where the 1s indicate starting locations of agents following the numbers above.


library(data.table) library(raster) library(quickPlot) set.seed(1234) Ntypes <- 4 ras <- randomPolygons(numTypes = Ntypes) if (interactive()) { clearPlot() Plot(ras) }
# Use numPerPatchTable patchDT <- data.table(pops = 1:Ntypes, = c(1, 3, 5, 7)) rasAgents <- specificNumPerPatch(ras, patchDT) rasAgents[] <- 0 library(testthat)
#> #> Attaching package: ‘testthat’
#> The following objects are masked from ‘package:magrittr’: #> #> equals, is_less_than, not
expect_true(all(unname(table(ras[rasAgents])) == patchDT$ # Use numPerPatchMap rasPatches <- ras for (i in 1:Ntypes) { rasPatches[rasPatches==i] <- patchDT$[i] } if (interactive()) { clearPlot() Plot(ras, rasPatches) }
rasAgents <- specificNumPerPatch(ras, numPerPatchMap = rasPatches) rasAgents[] <- 0 if (interactive()) { clearPlot() Plot(rasAgents) }