|
9 | 9 | #'
|
10 | 10 | #' @param SS fetch data from Selected Set in NASIS or from the entire local
|
11 | 11 | #' database (default: `TRUE`)
|
12 |
| -#' @param mixColors should mixed colors be calculated (Default: `TRUE`) where multiple colors are populated for the same moisture state in a horizon? `FALSE` takes the dominant color based on `colorpct` or first record based on horizon ID (`phiid`) sorting for "moist" and "dry" state. Pedon Horizon Color records without a moisture state populated are ignored. |
| 12 | +#' @param method Aggregation method to handle multiple colors per horizon and moisture state. Default `"dominant"` for dominant condition (or first record) within moisture state. Other options include `"mixed"` to calculate mixture using `simplifyColorData()` and `"none"` to do no aggregation (returns a long format representation that may have multiple values per horizon and moisture state) |
| 13 | +#' @param mixColors Deprecated. See `method`. Should mixed colors be calculated where multiple colors are populated for the same moisture state in a horizon? Default `FALSE` takes the dominant color based on `colorpct` or first record based on horizon ID (`phiid`) sorting for "moist" and "dry" state. Pedon Horizon Color records without a moisture state populated are ignored. |
13 | 14 | #' @param dsn Optional: path to local SQLite database containing NASIS
|
14 | 15 | #' table structure; default: `NULL`
|
15 | 16 | #' @return A data.frame with the results.
|
|
19 | 20 | #' \code{\link{get_site_data_from_NASIS_db}}
|
20 | 21 | #' @keywords manip
|
21 | 22 | #' @export get_colors_from_NASIS_db
|
22 |
| -get_colors_from_NASIS_db <- function(SS = TRUE, mixColors = TRUE, dsn = NULL) { |
| 23 | +get_colors_from_NASIS_db <- function(SS = TRUE, method = "dominant", mixColors = FALSE, dsn = NULL) { |
23 | 24 |
|
| 25 | + if (!missing(mixColors)) { |
| 26 | + .Deprecated(msg = "`mixColors` argument is deprecated, see `method` argument for additional aggregation options") |
| 27 | + if (isTRUE(mixColors)) { |
| 28 | + method <- "mixed" |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + method <- match.arg(method, c("dominant", "mixed", "none")) |
| 33 | + |
24 | 34 | # unique-ness enforced via peiid (pedon-level) and phiid (horizon-level)
|
25 | 35 | # TODO: is alias of colorpct necessary?
|
26 | 36 | q <- "SELECT peiid, phiid, colormoistst, colorpct as pct, colorhue, colorvalue, colorchroma
|
@@ -53,11 +63,13 @@ get_colors_from_NASIS_db <- function(SS = TRUE, mixColors = TRUE, dsn = NULL) {
|
53 | 63 | d$colorchroma <- as.numeric(as.character(d$colorchroma))
|
54 | 64 |
|
55 | 65 | # sanity check, only attempt to simplify colors if there are > 1 rows
|
56 |
| - if (nrow(d) > 1 && mixColors) { |
| 66 | + if (nrow(d) > 1 && (method == "mixed")) { |
57 | 67 | # mix colors as-needed, mixing done in CIE LAB space
|
58 | 68 | d.final <- simplifyColorData(d, id.var = 'phiid', wt = 'pct')
|
59 |
| - } else { |
| 69 | + } else if (method == "dominant") { |
60 | 70 | d.final <- .dominantColors(d)
|
| 71 | + } else { |
| 72 | + d.final <- d |
61 | 73 | }
|
62 | 74 |
|
63 | 75 | # done
|
|
0 commit comments