Horizons Above or Below

hzAbove(x, ..., offset = 1, SPC = TRUE, simplify = SPC)

hzBelow(x, ..., offset = 1, SPC = TRUE, simplify = SPC)

hzOffset(x, hzid, offset, SPC = FALSE, simplify = TRUE)

Arguments

x

A SoilProfileCollection

...

Comma-separated set of R expressions that evaluate as TRUE or FALSE in context of horizon data frame. Length for individual expressions matches number of horizons, in x.

offset

Integer offset in terms of SoilProfileCollection [,j] (horizon/slice) index

SPC

Return a SoilProfileCollection? Default TRUE for horizon_* methods.

simplify

If TRUE return a vector (all elements combined), or a list (1 element per profile). If SPC is TRUE then simplify is TRUE.

hzid

A vector of target horizon IDs. These are calculated from ... for horizon_*() methods

Value

A SoilProfileCollection (when SPC = TRUE) or a vector of horizon row indices (when SPC = FALSE and simplify = TRUE) or a list (when SPC = FALSE and simplify = FALSE))

Details

To minimize likelihood of issues with non-standard evaluation context, especially when using hzAbove()/hzBelow() inside another function, all expressions used in ... should be in terms of variables that are in the horizon data frame.

Examples

data(sp4)
depths(sp4) <- id ~ top + bottom

# get the horizon above the last horizon (j-index of bottom horizon minus 1)
hzAbove(sp4, hzID(sp4) %in% getLastHorizonID(sp4))
#> Error in (function (classes, fdef, mtable) {    methods <- .findInheritedMethods(classes, fdef, mtable)    if (length(methods) == 1L)         return(methods[[1L]])    else if (length(methods) == 0L) {        cnames <- paste0("\"", vapply(classes, as.character,             ""), "\"", collapse = ", ")        stop(gettextf("unable to find an inherited method for function %s for signature %s",             sQuote(fdef@generic), sQuote(cnames)), domain = NA)    }    else stop("Internal error in finding inherited methods; didn't return a unique method",         domain = NA)})(list("data.frame"), new("standardGeneric", .Data = function (object) standardGeneric("hzID"), generic = structure("hzID", package = "aqp"),     package = "aqp", group = list(), valueClass = character(0),     signature = "object", default = NULL, skeleton = (function (object)     stop(gettextf("invalid call in method dispatch to '%s' (no default method)",         "hzID"), domain = NA))(object)), <environment>): unable to find an inherited method for function ‘hzID’ for signature ‘"data.frame"’

# get horizons below the last horizon (none; j-index of bottom horizon plus 1)
hzBelow(sp4, hzID(sp4) %in% getLastHorizonID(sp4))
#> Error in (function (classes, fdef, mtable) {    methods <- .findInheritedMethods(classes, fdef, mtable)    if (length(methods) == 1L)         return(methods[[1L]])    else if (length(methods) == 0L) {        cnames <- paste0("\"", vapply(classes, as.character,             ""), "\"", collapse = ", ")        stop(gettextf("unable to find an inherited method for function %s for signature %s",             sQuote(fdef@generic), sQuote(cnames)), domain = NA)    }    else stop("Internal error in finding inherited methods; didn't return a unique method",         domain = NA)})(list("data.frame"), new("standardGeneric", .Data = function (object) standardGeneric("hzID"), generic = structure("hzID", package = "aqp"),     package = "aqp", group = list(), valueClass = character(0),     signature = "object", default = NULL, skeleton = (function (object)     stop(gettextf("invalid call in method dispatch to '%s' (no default method)",         "hzID"), domain = NA))(object)), <environment>): unable to find an inherited method for function ‘hzID’ for signature ‘"data.frame"’