GISSM_get_KilledBySoilLayers: Determine if all conditions across rooted soil layers are...

View source: R/RcppExports.R

GISSM_get_KilledBySoilLayersR Documentation

Determine if all conditions across rooted soil layers are deadly

Description

Function that checks whether all relevant (those with roots) soil layers are under conditions of mortality (kill.conditions) for each day of a given year

Usage

GISSM_get_KilledBySoilLayers(relevantLayers, kill_conditions)

Arguments

relevantLayers

An integer vector, usually of length 365 or 366 (days).

kill_conditions

A m x p logical matrix with m >= length(relevantLayers) and p represents the number of simulated soil layers, i.e., p >= max(relevantLayers, na.rm = TRUE).

Details

relevantLayers takes either NA if no soil layers should be considered (e.g., because not yet germinated), or an integer number between 1 and the number of simulated soil layers. The number indicates the depth to which a seedling has grown roots and over which layers kill.conditions will be evaluated.

Value

A logical vector of the length of relevantLayers with values containing NA for days when conditions were not evaluated, TRUE if all relevant soil layers (columns) of kill.conditions were TRUE, and with FALSE otherwise

Note

The Rcpp version of the function is about 165x faster than the version previous to commit 6344857a9cdb08acf68fa031c43cf4a596613aad 'Small speed improvements' and about 70x faster than the R version. The Rcpp version also reduced the memory footprint by a factor of 200.

References

Schlaepfer, D.R., Lauenroth, W.K. & Bradford, J.B. (2014). Modeling regeneration responses of big sagebrush (Artemisia tridentata) to abiotic conditions. Ecol Model, 286, 66-77.

Examples

 # The \pkg{Rcpp} function is equivalent to the following R version
    get_KilledBySoilLayers_R <- function(relevantLayers, kill.conditions) {
      vapply(
        seq_along(relevantLayers),
        function(k) {
          if (all(is.finite(relevantLayers[k]))) {
            all(as.logical(kill.conditions[k, seq_len(relevantLayers[k])]))
          } else NA
        },
        FUN.VALUE = NA
      )
    }


DrylandEcology/rSW2funs documentation built on June 28, 2023, 2:51 a.m.