
Map simulate_occurrences() over multiple species
Source: R/map_simulate_occurrences.R
map_simulate_occurrences.RdThis function executes simulate_occurrences() over multiple rows of a
dataframe, representing different species, with potentially
different function arguments over multiple columns.
Arguments
- df
A dataframe containing multiple rows, each representing a different species. The columns are function arguments with values used for mapping
simulate_occurrences()for each species. Columns not used by this function will be retained in the output.- nested
Logical. If
TRUE(default), retains list-column containing sf objects calculated bysimulate_occurrences(). Otherwise, expands this list-column into rows and columns.- arg_list
A named list or
NA. IfNA(default), the function assumes column names indfare identical to argument names ofsimulate_occurrences()and the function specified in itstemporal_functionargument. If column names differ, they must be specified as a named list where the names are the argument names ofsimulate_occurrences()or the function specified in itstemporal_functionargument, and the associated values are the corresponding column names indf.- progress
Logical. Whether to show a progress bar. Set to
TRUEto display a progress bar,FALSE(default) to suppress it.
Value
In case of nested = TRUE, a dataframe identical to df, with an
extra list-column called occurrences containing an sf object with POINT
geometry for each row computed by simulate_occurrences(). In case of
nested = FALSE, this list-column is expanded into additional rows and
columns.
See also
Other multispecies:
generate_taxonomy(),
map_add_coordinate_uncertainty(),
map_filter_observations(),
map_grid_designation(),
map_sample_observations()
Examples
if (FALSE) { # \dontrun{
# Load packages
library(sf)
library(dplyr)
# Create polygon
plgn <- st_polygon(list(cbind(c(5, 10, 8, 2, 3, 5), c(2, 1, 7, 9, 5, 2))))
## Example with simple column names
# Specify dataframe for 3 species with custom function arguments
species_dataset_df <- tibble(
taxonID = c("species1", "species2", "species3"),
species_range = rep(list(plgn), 3),
initial_average_occurrences = c(50, 100, 200),
n_time_points = rep(6, 3),
temporal_function = c(simulate_random_walk, simulate_random_walk, NA),
sd_step = c(1, 1, NA),
spatial_pattern = "random",
seed = 123)
# Simulate occurrences
sim_occ_nested <- map_simulate_occurrences(df = species_dataset_df)
sim_occ_nested
## Example with deviating column names
# Specify dataframe for 3 species with custom function arguments
species_dataset_df2 <- species_dataset_df %>%
rename(polygon = species_range,
sd = sd_step)
# Create named list for argument conversion
arg_conv_list <- list(
species_range = "polygon",
sd_step = "sd"
)
# Simulate occurrences
map_simulate_occurrences(
df = species_dataset_df2,
arg_list = arg_conv_list)
} # }