Skip to content

Commit 497e30d

Browse files
sprintf() to formatMunsell()
1 parent 1daa2d9 commit 497e30d

16 files changed

Lines changed: 30 additions & 20 deletions

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: aqp
2-
Version: 2.3.1
2+
Version: 2.3.2
33
Title: Algorithms for Quantitative Pedology
44
Authors@R: c(person(given="Dylan", family="Beaudette", role = c("aut", "cre"), email = "dylan.beaudette@usda.gov", comment = c(ORCID="0009-0008-2780-4785")),
55
person(given="Pierre", family="Roudier", email="roudierp@landcareresearch.co.nz", role = c("aut", "ctb")),

R/colorChart.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#' )
4242
#'
4343
#' # combine hue, value, chroma into standard Munsell notation
44-
#' ric <- sprintf("%s %s/%s", ric$hue, ric$value, ric$chroma)
44+
#' ric <- formatMunsell(ric$hue, ric$value, ric$chroma)
4545
#'
4646
#' # note that chip frequency-based size is disabled
4747
#' # because all chips have equal frequency

R/colorVariation.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ colorVariation <- function(m, method = c('frequency', 'centroid', 'L1', 'referen
163163

164164
# convert back to Munsell notation for colorContrast()
165165
m.centroid <- col2Munsell(t(lab.centroid), space = 'CIELAB')
166-
m.centroid <- sprintf("%s %s/%s", m.centroid$hue, m.centroid$value, m.centroid$chroma)
166+
m.centroid <- formatMunsell(m.centroid$hue, m.centroid$value, m.centroid$chroma)
167167

168168
# color contrast vs. centroid
169169
cc <- colorContrast(m1 = wt.m, m2 = rep(m.centroid, times = length(wt)))
@@ -191,7 +191,7 @@ colorVariation <- function(m, method = c('frequency', 'centroid', 'L1', 'referen
191191

192192
# convert back to Munsell notation for colorContrast()
193193
m.centroid <- col2Munsell(lab.centroid, space = 'CIELAB')
194-
m.centroid <- sprintf("%s %s/%s", m.centroid$hue, m.centroid$value, m.centroid$chroma)
194+
m.centroid <- formatMunsell(m.centroid$hue, m.centroid$value, m.centroid$chroma)
195195

196196
# color contrast vs. centroid
197197
cc <- colorContrast(m1 = wt.m, m2 = rep(m.centroid, times = length(wt)))

R/contrastChart.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ contrastChart <- function(m, hues, ccAbbreviate = 1, style = 'hue', gridLines =
108108

109109
# convert into hex notation for plotting
110110
x$color <- munsell2rgb(x$hue, x$value, x$chroma)
111-
x$munsell <- sprintf("%s %s/%s", x$hue, x$value, x$chroma)
111+
x$munsell <- formatMunsell(x$hue, x$value, x$chroma)
112112

113113
# re-level hues according to color contrast guidance
114114
hh <- unique(x$hue)

R/equivalentMunsellChips.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@
143143

144144
# create a nice lookup table to add to aqp
145145
equivalent_munsell <- xin1
146-
names(equivalent_munsell) <- sprintf("%s %s/%s", munsell$hue, munsell$value, munsell$chroma)
146+
names(equivalent_munsell) <- formatMunsell(munsell$hue, munsell$value, munsell$chroma)
147147

148148
# this is only 107kB written to Rda
149-
save(equivalent_munsell, file="data/equivalent_munsell.rda")
149+
save(equivalent_munsell, file = "data/equivalent_munsell.rda")
150150

151151
return(equivalent_munsell)
152152
}
@@ -215,7 +215,7 @@
215215
#' par(mar=c(0,0,1,1))
216216
#'
217217
#' pie(rep(1, nrow(veryred)), col = with(veryred, munsell2rgb(hue, value, chroma)),
218-
#' label = with(veryred, sprintf("%s %s/%s", hue, value, chroma)))
218+
#' label = with(veryred, formatMunsell(hue, value, chroma)))
219219
#'
220220
#' table(veryred$hue) # 2 hues
221221
#' #>
@@ -250,7 +250,7 @@ equivalentMunsellChips <- function(hue = NULL, value = NULL, chroma = NULL) {
250250
munsell$chroma == chipdata$chroma[x])
251251
})
252252
res <- lapply(lidx, function(i) munsell[equivalent_munsell[i][[1]],])
253-
names(res) <- sprintf("%s %s/%s", hue, value, chroma)
253+
names(res) <- formatMunsell(hue, value, chroma)
254254
rownames(res) <- NULL
255255
return(res)
256256
}

R/launderMunsell.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
#' * '10YR 2/0' -> 'N 2/0'
1515
#' * 'N 4/1 -> 'N 4/0'
1616
#' * '5Z 3/3' -> NA
17+
#' * '5YR 3/' -> NA (hues other than N must have a valid chroma)
1718
#'
19+
#' See [formatMunsell()] for additional details.
1820
#'
1921
#' @param m character vector of Munsell colors
2022
#' @param verbose logical, optionally return a `data.frame` comparing modifications
@@ -50,6 +52,9 @@
5052
#' # missing chroma, not N => NA
5153
#' launderMunsell('2.5Y 4/')
5254
#'
55+
#' # invalid chroma => NA
56+
#' launderMunsell('2.5Y 4/A')
57+
#'
5358
launderMunsell <- function(m, verbose = FALSE, ...) {
5459

5560
# split into components
@@ -73,7 +78,6 @@ launderMunsell <- function(m, verbose = FALSE, ...) {
7378

7479
# combine back into standard notation
7580
# following conventions
76-
# .res <- sprintf("%s %s/%s", .p$hue, .p$value, .p$chroma)
7781
.res <- formatMunsell(hue = .p$hue, value = .p$value, chroma = .p$chroma, ...)
7882

7983
# optionally combine into a data.frame for inspection

R/mixMunsell.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ mixMunsell <- function(x, w = rep(1, times = length(x)) / length(x), mixingMetho
379379
} else {
380380
# mx is a data.frame
381381
res <- data.frame(
382-
munsell = sprintf("%s %s/%s", mx$hue, mx$value, mx$chroma),
382+
munsell = formatMunsell(mx$hue, mx$value, mx$chroma),
383383
distance = mx$sigma,
384384
scaledDistance = NA,
385385
distanceMetric = 'dE00',

R/simulateColor.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393

9494
# convert into hex notation for plotting
9595
x$color <- munsell2rgb(x$hue, x$value, x$chroma)
96-
x$munsell <- sprintf("%s %s/%s", x$hue, x$value, x$chroma)
96+
x$munsell <- formatMunsell(x$hue, x$value, x$chroma)
9797

9898
# re-level hues according to color contrast guidance
9999
hh <- unique(x$hue)

R/soilColorIndices.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#' site(sp1) <- ~ group
2424
#'
2525
#' # use Munsell color notation as horizon name
26-
#' sp1$m <- sprintf("%s %s/%s", sp1$hue, sp1$value, sp1$chroma)
26+
#' sp1$m <- formatMunsell(sp1$hue, sp1$value, sp1$chroma)
2727
#'
2828
#' # compute indices
2929
#' # merged into `sp1` with left-join on hzidname(sp1)

R/soilColorSignature.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@
328328
#' depths(sp1) <- id ~ top + bottom
329329
#'
330330
#' # Munsell notation
331-
#' sp1$m <- sprintf("%s %s/%s", sp1$hue, sp1$value, sp1$chroma)
331+
#' sp1$m <- formatMunsell(sp1$hue, sp1$value, sp1$chroma)
332332
#'
333333
#' # extract color signature
334334
#' pig <- soilColorSignature(sp1, color = 'm')

0 commit comments

Comments
 (0)