|
12 | 12 | #' @examples
|
13 | 13 | #' extractSMR(c("aquic haploxeralfs", "typic epiaqualfs", "humic inceptic eutroperox"))
|
14 | 14 | 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 | + |
16 | 57 | if (as.is) {
|
17 | 58 | return(res)
|
18 | 59 | }
|
| 60 | + |
19 | 61 | res <- factor(res, levels = SoilMoistureRegimeLevels(as.is = TRUE), ordered = ordered)
|
20 | 62 | if (droplevels) {
|
21 | 63 | return(droplevels(res))
|
22 | 64 | }
|
| 65 | + |
23 | 66 | names(res) <- taxon
|
24 | 67 | res
|
25 | 68 | }
|
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 |
| - ## NB: currently there is no formative element connotation for "peraquic" soils |
55 |
| - data.frame(element = c("per", "ids", "aqu", "torr", "ud", |
56 |
| - "ust", "xer", "torri", "ud", "ust", |
57 |
| - "xer", "aqu", "udic", "ustic", "xeric", |
58 |
| - "aquic"), |
59 |
| - level = c("suborder", "order", "suborder", "suborder", "suborder", |
60 |
| - "suborder", "suborder", "greatgroup", "greatgroup", "greatgroup", |
61 |
| - "greatgroup", "greatgroup", "subgroup", "subgroup", "subgroup", |
62 |
| - "subgroup"), |
63 |
| - connotation = c("perudic", "aridic (torric)", "aquic", "aridic (torric)", "udic", |
64 |
| - "ustic", "xeric", "aridic (torric)", "udic", "ustic", |
65 |
| - "xeric", "aquic", "udic", "ustic", "xeric", |
66 |
| - "aquic"), |
67 |
| - stringsAsFactors = FALSE) |
68 |
| -} |
0 commit comments