Skip to content

Commit 481db77

Browse files
committed
extractSMR:
- add support for SMR described only at subgroup level - add aquic ("sapr", "hem", "fibr") and peraquic ("wass") suborders
1 parent dff0043 commit 481db77

File tree

1 file changed

+44
-37
lines changed

1 file changed

+44
-37
lines changed

R/extractSMR.R

+44-37
Original file line numberDiff line numberDiff line change
@@ -12,50 +12,57 @@
1212
#' @examples
1313
#' extractSMR(c("aquic haploxeralfs", "typic epiaqualfs", "humic inceptic eutroperox"))
1414
extractSMR <- function(taxon, as.is = FALSE, droplevels = FALSE, ordered = TRUE) {
15-
res <- vapply(taxon, .extractSMR, character(1))
15+
16+
.get_SMR_element_connotation <- function() {
17+
data.frame(element = c("ids",
18+
"per", "aqu", "torr", "ud", "ust", "xer", "sapr", "hem", "fibr", "wass",
19+
"torri", "ud", "ust", "xer", "aqu",
20+
"udic", "ustic", "xeric"),
21+
level = c("order",
22+
"suborder", "suborder", "suborder", "suborder", "suborder", "suborder", "suborder", "suborder", "suborder", "suborder",
23+
"greatgroup", "greatgroup", "greatgroup", "greatgroup", "greatgroup",
24+
"subgroup", "subgroup", "subgroup"),
25+
connotation = c("aridic (torric)",
26+
"perudic", "aquic", "aridic (torric)", "udic", "ustic", "xeric", "aquic", "aquic", "aquic", "peraquic",
27+
"aridic (torric)", "udic", "ustic", "xeric", "aquic",
28+
"udic", "ustic", "xeric"),
29+
stringsAsFactors = FALSE)
30+
}
31+
32+
# get SMR formative element connotation LUT
33+
co <- .get_SMR_element_connotation()
34+
35+
res <- vapply(taxon, function(taxon) {
36+
37+
# extract formative elements
38+
el <- FormativeElements(taxon)
39+
40+
# determine taxon level and position
41+
el$defs$hierarchy <- level_hierarchy(el$defs$level)
42+
th <- min(el$defs$hierarchy, na.rm = TRUE)
43+
44+
# only consider SMR formative elements at or below taxon level
45+
el$defs <- el$defs[el$defs$element %in% co$element & th <= el$defs$level, ]
46+
47+
# THEN get highest level taxon SMR connotation
48+
co <- co[co$element %in% el$defs$element &
49+
co$level %in% el$defs$level &
50+
co$level == suppressWarnings(max(el$defs$hierarchy, na.rm = TRUE)), ]
51+
nrx <- nrow(co)
52+
if (nrx == 1) {
53+
co$connotation
54+
} else NA_character_
55+
}, character(1))
56+
1657
if (as.is) {
1758
return(res)
1859
}
60+
1961
res <- factor(res, levels = SoilMoistureRegimeLevels(as.is = TRUE), ordered = ordered)
2062
if (droplevels) {
2163
return(droplevels(res))
2264
}
65+
2366
names(res) <- taxon
2467
res
2568
}
26-
27-
.extractSMR <- function(taxon) {
28-
29-
# extract formative elements
30-
el <- FormativeElements(taxon)
31-
32-
# determine taxon level and position
33-
el$defs$hierarchy <- level_hierarchy(el$defs$level)
34-
th <- min(el$defs$hierarchy, na.rm = TRUE)
35-
36-
# get SMR formative element connotation LUT
37-
co <- .get_SMR_element_connotation()
38-
39-
# only consider SMR formative elements at or below taxon level
40-
el$defs <- el$defs[el$defs$element %in% co$element & th <= el$defs$level,]
41-
42-
# THEN get highest level taxon SMR connotation
43-
co <- co[co$element %in% el$defs$element &
44-
co$level %in% el$defs$level &
45-
co$level == suppressWarnings(max(el$defs$hierarchy, na.rm = TRUE)), ]
46-
nrx <- nrow(co)
47-
if (nrx == 1) {
48-
# todo handle per+aqu and per+ud
49-
co$connotation
50-
} else NA_character_
51-
}
52-
53-
.get_SMR_element_connotation <- function() {
54-
# x <- get_ST_formative_elements()
55-
# x[grepl("SMR|wetness", x$connotation) & x$level != "subgroup",][c("element","level")]
56-
## NB: currently there is no formative element connotation for "peraquic" soils
57-
data.frame(element = c("per", "ids", "aqu", "torr", "ud", "ust", "xer", "torri", "ud", "ust", "xer", "aqu"),
58-
level = c("suborder", "order", "suborder", "suborder", "suborder", "suborder", "suborder", "greatgroup", "greatgroup", "greatgroup", "greatgroup", "greatgroup"),
59-
connotation = c("perudic", "aridic (torric)", "aquic", "aridic (torric)", "udic", "ustic", "xeric", "aridic (torric)", "udic", "ustic", "xeric", "aquic"),
60-
stringsAsFactors = FALSE)
61-
}

0 commit comments

Comments
 (0)