diff --git a/.github/workflows/R-CMD-check.yml b/.github/workflows/R-CMD-check.yml index a9293734..12991761 100644 --- a/.github/workflows/R-CMD-check.yml +++ b/.github/workflows/R-CMD-check.yml @@ -62,14 +62,10 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: any::rcmdcheck, any::remotes, terra=?ignore-before-r=4.1.0, local::. + extra-packages: any::rcmdcheck, any::remotes, terra=?ignore-before-r=4.1.0, local::., brownag/soilDBdata # upgrade: 'TRUE' ## NB: required to force building of source packages needs: check - - name: Install soilDBdata off GitHub - run: remotes::install_github("brownag/soilDBdata", dependencies = FALSE, build = FALSE) - shell: Rscript {0} - - name: Install aqp off GitHub (devel only) if: matrix.config.r == 'devel' run: | diff --git a/NAMESPACE b/NAMESPACE index d4c788e4..3211bc33 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -172,12 +172,12 @@ importFrom(aqp,SoilTextureLevels) importFrom(aqp,`depths<-`) importFrom(aqp,`site<-`) importFrom(aqp,checkHzDepthLogic) +importFrom(aqp,col2Munsell) importFrom(aqp,hzDistinctnessCodeToOffset) importFrom(aqp,munsell2rgb) importFrom(aqp,parseMunsell) importFrom(aqp,pbindlist) importFrom(aqp,plotSPC) -importFrom(aqp,rgb2munsell) importFrom(curl,curl_download) importFrom(curl,has_internet) importFrom(curl,new_handle) diff --git a/R/estimateColorMixture.R b/R/estimateColorMixture.R index 911a88f6..43d37362 100644 --- a/R/estimateColorMixture.R +++ b/R/estimateColorMixture.R @@ -15,11 +15,13 @@ #' #' @param wt fractional weights, usually area of hz face #' -#' @param backTransform logical, should the mixed sRGB representation of soil color be transformed to closest Munsell chips? This is performed by [aqp::rgb2munsell()] default: `FALSE` +#' @param backTransform logical, should the mixed sRGB representation of soil color be transformed to closest Munsell chips? This is performed by [aqp::col2Munsell()] default: `FALSE` #' #' @return A data.frame containing estimated color mixture #' @export estimateColorMixture -#' +#' +#' @importFrom aqp col2Munsell +#' estimateColorMixture <- function(x, wt = 'pct', backTransform = FALSE) { ## TODO: account for `backTransform == TRUE`, different return structure @@ -68,10 +70,9 @@ estimateColorMixture <- function(x, wt = 'pct', backTransform = FALSE) { # performance penalty due to color distance eval against entire Munsell library if(backTransform) { - # convert with best available metric - ## TODO: once aqp 2.0.2 is on CRAN use col2Munsell() - # m <- col2Munsell(mixed.color[, c('r', 'g', 'b')]) - m <- rgb2munsell(mixed.color[, c('r', 'g', 'b')]) + # convert sRGB -> Munsell + # requires >= aqp 2.0.2 + m <- col2Munsell(mixed.color[, c('r', 'g', 'b')]) # adjust names to match NASIS names(m) <- c("colorhue", "colorvalue", "colorchroma", "sigma") diff --git a/R/simplifyColorData.R b/R/simplifyColorData.R index 696cdb43..3652186b 100644 --- a/R/simplifyColorData.R +++ b/R/simplifyColorData.R @@ -48,12 +48,12 @@ #' @param wt a character vector with the name of the column containing color #' weights for mixing #' @param bt logical, should the mixed sRGB representation of soil color be -#' transformed to closest Munsell chips? This is performed by `aqp::rgb2munsell` +#' transformed to closest Munsell chips? This is performed by [aqp::col2Munsell()] #' @author D.E. Beaudette #' @keywords manip #' @export #' @importFrom grDevices rgb -#' @importFrom aqp munsell2rgb rgb2munsell +#' @importFrom aqp munsell2rgb col2Munsell simplifyColorData <- function(d, id.var = 'phiid', wt = 'colorpct', bt = FALSE) { # sanity check: must contain at least 1 row @@ -112,9 +112,9 @@ simplifyColorData <- function(d, id.var = 'phiid', wt = 'colorpct', bt = FALSE) mixed.dry <- dry.colors[dry.mix.idx, .SD, .SDcols = c(id.var, mix.vars)] mixed.dry <- mixed.dry[, estimateColorMixture(.SD, wt = wt, backTransform = bt), by = id.var] - # back-transform mixture to Munsell using best-available method - ## TODO: once aqp 2.0.2 is on CRAN use col2Munsell() - m <- aqp::rgb2munsell(as.data.frame(mixed.dry[, .SD, .SDcols = c('r', 'g', 'b')])) + # convert sRGB -> Munsell + # requires >= aqp 2.0.2 + m <- col2Munsell(as.data.frame(mixed.dry[, .SD, .SDcols = c('r', 'g', 'b')])) # adjust names to match NASIS names(m) <- c("colorhue", "colorvalue", "colorchroma", "sigma") @@ -151,9 +151,9 @@ simplifyColorData <- function(d, id.var = 'phiid', wt = 'colorpct', bt = FALSE) mixed.moist <- moist.colors[moist.mix.idx, .SD, .SDcols = c(id.var, mix.vars)] mixed.moist <- mixed.moist[, estimateColorMixture(.SD, wt = wt, backTransform = bt), by = id.var] - # back-transform mixture to Munsell using best-available method - ## TODO: once aqp 2.0.2 is on CRAN use col2Munsell() - m <- rgb2munsell(as.data.frame(mixed.moist[, .SD, .SDcols = c('r', 'g', 'b')])) + # convert sRGB -> Munsell + # requires >= aqp 2.0.2 + m <- col2Munsell(as.data.frame(mixed.moist[, .SD, .SDcols = c('r', 'g', 'b')])) # adjust names to match NASIS names(m) <- c("colorhue", "colorvalue", "colorchroma", "sigma") diff --git a/man/estimateColorMixture.Rd b/man/estimateColorMixture.Rd index 21442ea2..0ed76807 100644 --- a/man/estimateColorMixture.Rd +++ b/man/estimateColorMixture.Rd @@ -11,7 +11,7 @@ estimateColorMixture(x, wt = "pct", backTransform = FALSE) \item{wt}{fractional weights, usually area of hz face} -\item{backTransform}{logical, should the mixed sRGB representation of soil color be transformed to closest Munsell chips? This is performed by \code{\link[aqp:rgb2munsell]{aqp::rgb2munsell()}} default: \code{FALSE}} +\item{backTransform}{logical, should the mixed sRGB representation of soil color be transformed to closest Munsell chips? This is performed by \code{\link[aqp:col2Munsell]{aqp::col2Munsell()}} default: \code{FALSE}} } \value{ A data.frame containing estimated color mixture diff --git a/man/simplifyColorData.Rd b/man/simplifyColorData.Rd index 93926780..6dee766b 100644 --- a/man/simplifyColorData.Rd +++ b/man/simplifyColorData.Rd @@ -17,7 +17,7 @@ that is unique among all horizons in \code{d}} weights for mixing} \item{bt}{logical, should the mixed sRGB representation of soil color be -transformed to closest Munsell chips? This is performed by \code{aqp::rgb2munsell}} +transformed to closest Munsell chips? This is performed by \code{\link[aqp:col2Munsell]{aqp::col2Munsell()}}} } \description{ Simplify multiple Munsell color observations associated with each horizon.