From 59dbe0b90a3ade1b600d3a322ee2b4f2f5d3ce37 Mon Sep 17 00:00:00 2001 From: Andrew Gene Brown Date: Mon, 8 Jan 2024 16:20:18 -0800 Subject: [PATCH] get_SDA_coecoclass: default constraint on ecoclasstypename should be `c("NRCS Rangeland Site", "NRCS Forestland Site")` --- NEWS.md | 7 +++++-- R/get_SDA_coecoclass.R | 20 ++++++++++---------- man/get_SDA_coecoclass.Rd | 4 ++-- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/NEWS.md b/NEWS.md index c755701b..60f539f8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# soilDB 2.8.1 (2024-01-08) +# soilDB 2.8.1 (2024-01-09) - `get_mapunit_from_NASIS()`, `get_lmuaoverlap_from_NASIS()` and `get_legend_from_NASIS()` gain `areatypename` argument used for filtering legends by `areatypename`. - Default results include `"Non-MLRA Soil Survey Area"` and `"MLRA Soil Survey Area"`. Set to `NULL` for no filter. @@ -9,7 +9,10 @@ - Upgraded SoilProfileCollection spatial promotion for aqp 2.0+ - Added 10 kPa, 33 kPa and 1500 kPa water content estimates to default variable sets for point and grid queries - `fetchSDA_spatial()` gains ability to query mapunit delineations by Ecological Site ID (`by.col="ecoclassid"`) - + - `get_SDA_coecoclass()` default `ecoclasstypename` is now `c("NRCS Rangeland Site", "NRCS Forestland Site")`, as this is the most common type of aggregation and is least prone to producing unusual composition-related errors due to duplications + - Fixed bug related to merging tables/integer data type + - Fixed bug in calculation of "Not assigned" fraction of mapunits which could result in negative aggregate component percentages below the default threshold + # soilDB 2.8.0 (2023-12-22) - Minimum {aqp} version set to v2.0.2. This is due to changes in the namespace related to `aqp::col2Munsell()`, to "encourage" users to update to the more efficient routines provided in {aqp} 2+ (if they haven't already), and prepare for future updates in the 2.x series. diff --git a/R/get_SDA_coecoclass.R b/R/get_SDA_coecoclass.R index 5b20a467..bca17bef 100644 --- a/R/get_SDA_coecoclass.R +++ b/R/get_SDA_coecoclass.R @@ -10,7 +10,7 @@ #' @param mukeys vector of map unit keys #' @param WHERE character containing SQL WHERE clause specified in terms of fields in `legend`, `mapunit`, `component` or `coecosite` tables, used in lieu of `mukeys` or `areasymbols` #' @param query_string Default: `FALSE`; if `TRUE` return a character string containing query that would be sent to SDA via `SDA_query` -#' @param ecoclasstypename If `NULL` no constraint on `ecoclasstypename` is used in the query. +#' @param ecoclasstypename Default: `c("NRCS Rangeland Site", "NRCS Forestland Site")`. If `NULL` no constraint on `ecoclasstypename` is used in the query. #' @param ecoclassref Default: `"Ecological Site Description Database"`. If `NULL` no constraint on `ecoclassref` is used in the query. #' @param not_rated_value Default: `"Not assigned"` #' @param miscellaneous_areas logical. Include miscellaneous areas (non-soil components)? @@ -21,7 +21,7 @@ get_SDA_coecoclass <- function(method = "None", areasymbols = NULL, mukeys = NULL, WHERE = NULL, query_string = FALSE, - ecoclasstypename = NULL, + ecoclasstypename = c("NRCS Rangeland Site", "NRCS Forestland Site"), ecoclassref = "Ecological Site Description Database", not_rated_value = "Not assigned", miscellaneous_areas = TRUE, @@ -148,7 +148,7 @@ get_SDA_coecoclass <- function(method = "None", .get_SDA_coecoclass_agg <- function(areasymbols = NULL, mukeys = NULL, - ecoclasstypename = NULL, + ecoclasstypename = c("NRCS Rangeland Site", "NRCS Forestland Site"), ecoclassref = "Ecological Site Description Database", not_rated_value = "Not assigned", miscellaneous_areas = TRUE, @@ -156,7 +156,7 @@ get_SDA_coecoclass <- function(method = "None", dsn = NULL, threshold = 0) { - comppct_r <- NULL; condpct_r <- NULL; compname <- NULL; ecoclasstypename <- NULL + comppct_r <- NULL; condpct_r <- NULL; compname <- NULL; # ecoclasstypename <- NULL areasymbol <- NULL; compnames <- NULL; unassigned <- NULL; mukey <- NULL; .N <- NULL; .SD <- NULL; .GRP <- NULL; @@ -199,21 +199,21 @@ get_SDA_coecoclass <- function(method = "None", res2 <- data.table::data.table(subset(res1, areasymbol != "US")) # remove FSG etc. some components have no ES assigned, but have other eco class - idx <- !res2$ecoclassref %in% c(not_rated_value, "Not assigned", "Ecological Site Description Database") & - !res2$ecoclasstypename %in% c(not_rated_value, "Not assigned", "NRCS Rangeland Site", "NRCS Forestland Site") + idx <- !res2$ecoclassref %in% c(not_rated_value, "Not assigned", ecoclassref) & + !res2$ecoclasstypename %in% c(not_rated_value, "Not assigned", ecoclasstypename) res2$ecoclassid[idx] <- not_rated_value res2$ecoclassref[idx] <- not_rated_value res2$ecoclassname[idx] <- not_rated_value res2$ecoclasstypename[idx] <- not_rated_value + .ECOCLASSTYPENAME <- ecoclasstypename + res3 <- res2[, list( condpct_r = sum(comppct_r, na.rm = TRUE), - compnames = paste0(compname[ecoclasstypename %in% c("NRCS Rangeland Site", - "NRCS Forestland Site")], + compnames = paste0(compname[ecoclasstypename %in% .ECOCLASSTYPENAME], collapse = ", "), - unassigned = paste0(compname[!ecoclasstypename %in% c("NRCS Rangeland Site", - "NRCS Forestland Site")], + unassigned = paste0(compname[!ecoclasstypename %in% .ECOCLASSTYPENAME], collapse = ", ") ), by = c("mukey", "ecoclassid", "ecoclassname")][, rbind( .SD[, 1:4], diff --git a/man/get_SDA_coecoclass.Rd b/man/get_SDA_coecoclass.Rd index 26c7e001..89e2523b 100644 --- a/man/get_SDA_coecoclass.Rd +++ b/man/get_SDA_coecoclass.Rd @@ -10,7 +10,7 @@ get_SDA_coecoclass( mukeys = NULL, WHERE = NULL, query_string = FALSE, - ecoclasstypename = NULL, + ecoclasstypename = c("NRCS Rangeland Site", "NRCS Forestland Site"), ecoclassref = "Ecological Site Description Database", not_rated_value = "Not assigned", miscellaneous_areas = TRUE, @@ -30,7 +30,7 @@ get_SDA_coecoclass( \item{query_string}{Default: \code{FALSE}; if \code{TRUE} return a character string containing query that would be sent to SDA via \code{SDA_query}} -\item{ecoclasstypename}{If \code{NULL} no constraint on \code{ecoclasstypename} is used in the query.} +\item{ecoclasstypename}{Default: \code{c("NRCS Rangeland Site", "NRCS Forestland Site")}. If \code{NULL} no constraint on \code{ecoclasstypename} is used in the query.} \item{ecoclassref}{Default: \code{"Ecological Site Description Database"}. If \code{NULL} no constraint on \code{ecoclassref} is used in the query.}