Skip to content

Commit ff1d837

Browse files
change n1_map to integer (#9) and update docs
1 parent 1c6d086 commit ff1d837

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

‎DESCRIPTION‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Suggests:
3535
VignetteBuilder: knitr
3636
Encoding: UTF-8
3737
LazyData: true
38-
RoxygenNote: 7.3.2
38+
RoxygenNote: 7.3.3
3939
Roxygen: list(markdown = TRUE, roclets = c("namespace", "rd", "srr::srr_stats_roclet"))
4040
Depends:
4141
R (>= 3.5.0)

‎R/disp.R‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ dists_tab <- function(N_pos, kernel, dist_resolution) {
234234

235235
#' Dispersal From Non-Empty Grid Cells
236236
#'
237-
#' This function calls [sq_disp_calc] with arguments passed from [disp] or
237+
#' This function calls `sq_disp_calc` with arguments passed from [disp] or
238238
#' without them (in case of parallel computations).
239239
#'
240240
#' Arguments for parallel computation are exported to clusters in [sim].
@@ -273,7 +273,7 @@ sq_disp <- function(
273273
#' Calculate Dispersal From Non-Empty Grid Cells
274274
#'
275275
#' This function calculates more possible target cells available
276-
#' from source cell `i` (if needed). Then, it uses [one_dist_sq_disp] function
276+
#' from source cell `i` (if needed). Then, it uses `one_dist_sq_disp` function
277277
#' to find cells that individuals will emigrate to.
278278
#'
279279
#' @param i integer vector of length 1; number of current source cell

‎R/initialise.R‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,11 @@ initialise <- function(
373373

374374
# output list ---------------------------------------------
375375
out <- list(
376-
n1_map = as.matrix(n1_map, wide = TRUE),
376+
n1_map = matrix(
377+
data = as.integer(values(n1_map)),
378+
nrow = nrow(n1_map),
379+
ncol = ncol(n1_map),
380+
byrow = TRUE),
377381
id = wrap(id),
378382
dist_bin = dist_bin,
379383
dist_resolution = dist_resolution,
@@ -454,7 +458,7 @@ K_n1_map_check <- function(K_map, n1_map, changing_env) {
454458

455459
#' Get Carrying Capacity For The First Time Step
456460
#'
457-
#' [K_get_init_values] returns all values from map of carrying capacity
461+
#' `K_get_init_values` returns all values from map of carrying capacity
458462
#' in the first time step.
459463
#'
460464
#' @inheritParams K_n1_map_check
@@ -484,19 +488,19 @@ K_get_init_values <- function(K_map, changing_env) {
484488

485489
#' Check For Precalculating Target Cells
486490
#'
487-
#' [calc_dist] checks if target cells should be precalculated
488-
#' and if so calls [dist_list].
491+
#' `calc_dist` checks if target cells should be precalculated
492+
#' and if so calls `dist_list`.
489493
#'
490494
#' @param id [`SpatRaster`][terra::SpatRaster-class]; contains all cells ids
491495
#' @param data_table matrix; contains information about all cells in current
492496
#' time points
493497
#' @param dist_resolution integer vector of length 1; dimension of one side of
494498
#' one cell of `id`; in case of an irregular grid or lon/lat raster it is calculated during [`initialisation`][`initialise`]
495-
#' calculated by [`calculate_dist_params`]
499+
#' calculated by `calculate_dist_params`
496500
#' @param dist_bin numeric vector of length 1 with value `>= 0`; in case of an irregular grid or lon/lat raster it is
497-
#' calculated by [`calculate_dist_params`]
501+
#' calculated by `calculate_dist_params`
498502
#' is equal to 0 if input maps are planar raster; if input maps are lon/lat it is calculated by
499-
#' rasters, `dist_bin` is calculated by [`calculate_dist_params`]
503+
#' rasters, `dist_bin` is calculated by `calculate_dist_params`
500504
#' @param id_within numeric vector; ids of cells inside the study area
501505
#' @inheritParams initialise
502506
#'
@@ -538,7 +542,7 @@ calc_dist <- function(
538542
#' Precalculating Target Cells For Dispersal
539543
#'
540544
#' `dist_list` prepares data for precalculation of target cells ids
541-
#' and then uses [`target_ids`] for calculation
545+
#' and then uses `target_ids` for calculation
542546
#'
543547
#' @inheritParams calc_dist
544548
#'
@@ -651,7 +655,7 @@ calculate_dist_params <- function(id, id_within, data_table, progress_bar, quiet
651655
#' from any cells of template `r`. It takes raster's dist_resolution into account.
652656
#'
653657
#' @param template template [`SpatRaster`][terra::SpatRaster-class] object
654-
#' @param dist_resolution parameter calculated by [`calculate_dist_params`] function
658+
#' @param dist_resolution parameter calculated by `calculate_dist_params` function
655659
#'
656660
#' @return numeric vector; numbers of target cells on every possible distance
657661
#' range

‎R/target_ids.R‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

22
#' Get Indexes Of Target Cells
33
#'
4-
#' [target_ids] finds all target cells available from given focal cell,
4+
#' `target_ids` finds all target cells available from given focal cell,
55
#' that lie within the maximum distance threshold (`max_dist`).
66
#'
77
#' @param idx integer vector of length 1; id of cell
8-
#' @param data integer matrix; necessary data (defined in [dist_list])
8+
#' @param data integer matrix; necessary data (defined in `dist_list`)
99
#' @param id_within integer vector; indexes of cells inside study area
10-
#' (defined in [dist_list])
10+
#' (defined in `dist_list`)
1111
#' @inheritParams dist_list
1212
#'
1313
#' @return List of target cells for each distance or `NULL` if there isn't any
@@ -95,7 +95,7 @@ get_vect_from_xy <- function(template, xy_cell, idx = NULL) {
9595
#' @param xy_vect [`SpatVector`][terra::SpatVector-class] object; represents current cell
9696
#' @param dist_resolution integer vector of length 1; dimension of one side of
9797
#' one cell of `id`; in case of an irregular grid or lon/lat raster it is
98-
#' calculated by [`calculate_dist_params`]
98+
#' calculated by `calculate_dist_params`
9999
#' @param min_dist_scaled integer vector of length 1; minimum distance to calculate target cell scaled by `dist_resolution`
100100
#' @param max_dist_scaled integer vector of length 1; maximum distance to calculate target cell scaled by `dist_resolution`
101101
#'
@@ -129,7 +129,7 @@ get_ds <- function(template, xy_vect, id_within, dist_resolution,
129129
ids <- id_within[in_range]
130130
ds <- d_within[in_range]
131131

132-
return(matrix(c(ids, ds), ncol = 2))
132+
return(matrix(as.integer(c(ids, ds)), ncol = 2))
133133
}
134134

135135

0 commit comments

Comments
 (0)