env_stack_transform: Coverts a list of 'SpatRaster' stacks where the elements are...

View source: R/env_stack_transform.R

env_stack_transformR Documentation

Coverts a list of 'SpatRaster' stacks where the elements are environmental variables and the layers are depths to a list of SpatRaster stacks where the elements are depths and the layers are environmental variables

Description

A user will likely already have environmental data organized into a list of 'spatRaster' stacks where each element is a different environmental variable and each layer corresponds to a depth slice for background sampling and extracting. However, the maxent_3D function requires the data be input as a list of 'spatRaster' stacks where each element corresponds to a depth slice and each layer is an environmental variable for the purpose of projecting the model back into geographic space, and this function has been developed for ease of conversion.

Usage

env_stack_transform(envs_all, envs_names)

Arguments

envs_all

a list of 'spatRaster' stacks where each element is a different environmental variable and each layer is a depth slice.

envs_names

A 'character' vector of the names of the environmental variables to be applied to the layers of the resulting list of 'spatRaster' stacks

Details

The extents of each environmental variable layer should match on a depth slice by depth slice basis.

Value

A list of 'spatRaster' stacks where each list element is a depth slice and each layer is an environmental variable.

Examples

library(terra)

# creating a list of spatRaster stacks where each element is an environmental variable
# and each layer is a depth

env1_d1 <- rast(ncol = 50, nrow = 50)
values(env1_d1) <- sample(c(1:100), size = 2500, replace = TRUE)
env2_d1 <- rast(ncol = 50, nrow = 50)
values(env2_d1) <- sample(c(1:100), size = 2500, replace = TRUE)
env1_d2 <- rast(ncol = 50, nrow = 50)
values(env1_d2) <- sample(c(1:100), size = 2500, replace = TRUE)
env2_d2 <- rast(ncol = 50, nrow = 50)
values(env2_d2) <- sample(c(1:100), size = 2500, replace = TRUE)

env1 <- c(env1_d1, env1_d2)
env2 <- c(env2_d1, env2_d2)
envs <- list(env1, env2)
envnames <- c("env1", "env2")

# Here's the function
result <- env_stack_transform(envs_all = envs, envs_names = envnames)


voluModel documentation built on July 23, 2026, 5:07 p.m.