Skip to content

Commit 5c83e0b

Browse files
hardening to missing suggests, like sharpshootR
1 parent 8a60208 commit 5c83e0b

File tree

6 files changed

+89
-159
lines changed

6 files changed

+89
-159
lines changed

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# aqp 2.2 (2025-02-04)
1+
# aqp 2.2 (2025-02-06)
22
* CRAN release
33
* fix for `hz_segment()` and `NCSP()` with _data.table_ `SoilProfileCollection` objects (#320)
44
* fix for `generalize.hz()` to handle missing depths better and added `na.rm` argument (#321)

R/aggregateColor.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@
7070
#' a <- aggregateColor(s, groups = 'slice', col = 'soil_color')
7171
#'
7272
#' # optionally plot with helper function
73-
#' if(require(sharpshootR))
74-
#' aggregateColorPlot(a)
73+
#' # from sharpshootR package
74+
#' if(requireNamespace('sharpshootR')) {
75+
#' sharpshootR::aggregateColorPlot(a)
76+
#' }
7577
#'
7678
#' # a more interesting example
7779
#' data(loafercreek, package = 'soilDB')

R/hzTransitionProbabilities.R

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -44,41 +44,6 @@
4444
#' (tp <- hzTransitionProbabilities(sp4, 'name'))
4545
#'
4646
#'
47-
#' \dontrun{
48-
#' ## plot TP matrix with functions from sharpshootR package
49-
#' library(sharpshootR)
50-
#' par(mar=c(0,0,0,0), mfcol=c(1,2))
51-
#' plotSPC(sp4, name = 'name', name.style = 'center-center')
52-
#' plotSoilRelationGraph(tp, graph.mode = 'directed', edge.arrow.size=0.5)
53-
#'
54-
#' ## demonstrate genhzTableToAdjMat usage
55-
#' data(loafercreek, package='soilDB')
56-
#'
57-
#' # convert contingency table -> adj matrix / TP matrix
58-
#' tab <- table(loafercreek$hzname, loafercreek$genhz)
59-
#' m <- genhzTableToAdjMat(tab)
60-
#'
61-
#' # plot
62-
#' par(mar=c(0,0,0,0), mfcol=c(1,1))
63-
#' plotSoilRelationGraph(m, graph.mode = 'directed', edge.arrow.size=0.5)
64-
#'
65-
#'
66-
#' ## demonstrate markovchain integration
67-
#' library(markovchain)
68-
#' tp.loops <- hzTransitionProbabilities(sp4, 'name', loopTerminalStates = TRUE)
69-
#'
70-
#' # init new markovchain from TP matrix
71-
#' mc <- new("markovchain", states=dimnames(tp.loops)[[1]], transitionMatrix = tp.loops)
72-
#'
73-
#' # simple plot
74-
#' plot(mc, edge.arrow.size=0.5)
75-
#'
76-
#' # check absorbing states
77-
#' absorbingStates(mc)
78-
#'
79-
#' # steady-state:
80-
#' steadyStates(mc)
81-
#' }
8247
#'
8348
hzTransitionProbabilities <- function(x, name = GHL(x, required = TRUE), loopTerminalStates = FALSE) {
8449

man/aggregateColor.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/hzTransitionProbabilities.Rd

Lines changed: 0 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/Introduction-to-SoilProfileCollection-Objects.Rmd

Lines changed: 81 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ vignette: >
66
%\VignetteEngine{knitr::rmarkdown}
77
%\VignetteEncoding{UTF-8}
88
---
9-
9+
1010
```{r setup, echo=FALSE, results='hide', warning=FALSE}
1111
knitr::opts_chunk$set(
12-
message = FALSE,
13-
warning = FALSE,
14-
background = '#F7F7F7',
15-
fig.align = 'center',
16-
dev = 'png',
17-
comment = "#>"
12+
message = FALSE,
13+
warning = FALSE,
14+
background = '#F7F7F7',
15+
fig.align = 'center',
16+
dev = 'png',
17+
comment = "#>"
1818
)
1919
options(width = 100, stringsAsFactors = FALSE, timeout = 600)
2020
@@ -75,9 +75,9 @@ print(sp4)
7575

7676
`SoilProfileCollection` objects are typically created by "promoting" `data.frame` objects (rectangular tables of data) that contain at least three essential columns:
7777

78-
1. an ID column uniquely identifying groups of horizons (e.g. pedons)
79-
2. horizon top boundaries
80-
3. horizon bottom boundaries
78+
1. an ID column uniquely identifying groups of horizons (e.g. pedons)
79+
2. horizon top boundaries
80+
3. horizon bottom boundaries
8181

8282
The `data.frame` is sorted internally according to the profile ID and horizon top boundary. Formula notation is used to define the columns used to promote a `data.frame` object:
8383

@@ -88,10 +88,10 @@ idcolumn ~ hz_top_column + hz_bottom_column
8888
## Rapid Templating
8989
Small collections of soil profiles can be described using text "templates" and `quickSPC()`. Templates take the form of:
9090

91-
* `ID:AAA|BBB|CCCCCC`: relative thickness specified by horizon designations, split by "|" symbol
92-
93-
* `ID:A-B-C`: horizons of random thickness specified by horizon designations, split by "-" symbol
94-
91+
* `ID:AAA|BBB|CCCCCC`: relative thickness specified by horizon designations, split by "|" symbol
92+
93+
* `ID:A-B-C`: horizons of random thickness specified by horizon designations, split by "-" symbol
94+
9595
The "ID:" prefix is optional, with unique IDs generated by the digest package when omitted.
9696

9797
```{r fig.width = 6}
@@ -118,35 +118,35 @@ plotSPC(s, name.style = 'center-center',
118118

119119
"Accessor" functions are used to extract specific components from within `SoilProfileCollection` objects.
120120

121-
* Methods that return a column name. These are useful for extracting depths, horizon designations, IDs, etc. before taking an SPC apart for a specific task.
122-
123-
+ `idname(sp4)`: extract profile ID name (column name used to init SPC)
124-
+ `horizonDepths(sp4)`: horizon top / bottom depth names (used to init SPC)
125-
+ `hzidname(sp4)`: horizon ID name (typically automatically built at init time)
126-
+ `hzdesgnname(sp4)`: horizon designation name (if set)
127-
+ `hztexclname(sp4)`: horizon texture class name (if set)
128-
129-
* Methods that return a vector of values.
130-
131-
+ `profile_id(sp4)`: profile IDs, in order
132-
+ `hzID(sp4)`: horizon IDs, in order
133-
+ `hzDesgn(sp4)`: horizon designations, in order
134-
135-
* Methods that return site/horizon attribute column names.
136-
137-
+ `names(sp4)`: site + horizon names concatenated into a single vector
138-
+ `horizonNames(sp4)`: horizon names
139-
+ `siteNames(sp4)`: site names
140-
141-
* Profile and horizon totals.
142-
143-
+ `length(sp4)`: number of profiles in collection
144-
+ `nrow(sp4)`: number of horizons in collection
121+
* Methods that return a column name. These are useful for extracting depths, horizon designations, IDs, etc. before taking an SPC apart for a specific task.
122+
123+
+ `idname(sp4)`: extract profile ID name (column name used to init SPC)
124+
+ `horizonDepths(sp4)`: horizon top / bottom depth names (used to init SPC)
125+
+ `hzidname(sp4)`: horizon ID name (typically automatically built at init time)
126+
+ `hzdesgnname(sp4)`: horizon designation name (if set)
127+
+ `hztexclname(sp4)`: horizon texture class name (if set)
128+
129+
* Methods that return a vector of values.
130+
131+
+ `profile_id(sp4)`: profile IDs, in order
132+
+ `hzID(sp4)`: horizon IDs, in order
133+
+ `hzDesgn(sp4)`: horizon designations, in order
145134

146-
* Other methods.
147-
148-
+ `depth_units(sp4)`: defaults to 'cm' at SPC creation
149-
+ `metadata(sp4)`: returns `list` object with base + optional (user-defined) metadata elements
135+
* Methods that return site/horizon attribute column names.
136+
137+
+ `names(sp4)`: site + horizon names concatenated into a single vector
138+
+ `horizonNames(sp4)`: horizon names
139+
+ `siteNames(sp4)`: site names
140+
141+
* Profile and horizon totals.
142+
143+
+ `length(sp4)`: number of profiles in collection
144+
+ `nrow(sp4)`: number of horizons in collection
145+
146+
* Other methods.
147+
148+
+ `depth_units(sp4)`: defaults to 'cm' at SPC creation
149+
+ `metadata(sp4)`: returns `list` object with base + optional (user-defined) metadata elements
150150

151151
# Horizon and Site Data
152152

@@ -156,10 +156,10 @@ Both site and horizon data are stored as `data.frame` within the SoilProfileColl
156156

157157
Columns from site or horizon tables can be accessed with the `$` syntax notation, similar to the `data.frame`. New data can be assigned to either table in the same manner, as long as the length of the new data is:
158158

159-
1. same length as the number of profiles in the collection (target is the site table)
160-
2. same length as the number of horizons in the collection (target is the horizon table)
161-
3. length 1; and selecting the target table requires `site(object)$new_column <- new_value` for new site data and `horizons(object)$new_column <- new value` for horizon
162-
159+
1. same length as the number of profiles in the collection (target is the site table)
160+
2. same length as the number of horizons in the collection (target is the horizon table)
161+
3. length 1; and selecting the target table requires `site(object)$new_column <- new_value` for new site data and `horizons(object)$new_column <- new value` for horizon
162+
163163
Assignment of new data to existing or new attributes can proceed as follows.
164164

165165
```{r hz_and_site_data}
@@ -355,13 +355,13 @@ z <- rebuildSPC(sp4)
355355

356356
`checkHzDepthLogic()` has the ability to perform logical tests on whole profiles or individual horizons. Four different tests are performed related to four common errors in horizon depths:
357357

358-
- bottom depth shallower than top depth
358+
- bottom depth shallower than top depth
359359

360-
- equal top and bottom depth
360+
- equal top and bottom depth
361361

362-
- missing (`NA`) top or bottom depth
362+
- missing (`NA`) top or bottom depth
363363

364-
- gap or overlap between adjacent horizons
364+
- gap or overlap between adjacent horizons
365365

366366
```{r}
367367
checkHzDepthLogic(sp4)
@@ -445,7 +445,7 @@ sp4[, , .LAST]
445445
`SoilProfileCollection` objects are combined by passing a list of objects to the `combine()` function.
446446

447447
Ideally all objects share the same internal structure, profile ID, horizon ID, depth units, and other parameters of a `SoilProfileCollection`. Manually subset the example data into 3 pieces, compile into a list, and then `combine` back together.
448-
448+
449449
```{r concatenation, eval=FALSE}
450450
# subset data into chunks
451451
s1 <- sp4[1:2, ]
@@ -636,12 +636,12 @@ explainPlotSPC(sp4, name = 'name', n = length(sp4) + 2)
636636
### Small SoilProfileCollections
637637

638638
Making quality figures with fewer than 5 soil profiles usually requires more customization of the basic call to `plotSPC`. In general, the following are a good starting point:
639-
640-
* shrink margins and disable clipping with `par`
641-
* adjust output graphic device (e.g. `png()`) dimensions and resolution
642-
* increase font size with `cex.names`
643-
* adjust sketch width with `width`, typically within 0.15-0.35
644-
* move depth axis to the left using negative `line` values, e.g. (`depth.axis = list(line = -2)`)
639+
640+
* shrink margins and disable clipping with `par`
641+
* adjust output graphic device (e.g. `png()`) dimensions and resolution
642+
* increase font size with `cex.names`
643+
* adjust sketch width with `width`, typically within 0.15-0.35
644+
* move depth axis to the left using negative `line` values, e.g. (`depth.axis = list(line = -2)`)
645645

646646
Get some example data from the Official Series Descriptions:
647647
```{r, fig.width=5, fig.height=6}
@@ -1087,9 +1087,9 @@ The `slab()` function is the simplest way to implement a change of depth support
10871087

10881088
The depth structure ("slabs") over which summaries are computed is defined with the `slab.structure` argument using:
10891089

1090-
* a single integer (e.g. `10`): data are aggregated over a regular sequence of 10-unit thickness slabs
1091-
* a vector of 2 integers (e.g. `c(50, 60)`): data are aggregated over depths spanning 50--60 units
1092-
* a vector of 3 or more integers (e.g. `c(0, 5, 10, 50, 100)`): data are aggregated over the depths spanning 0--5, 5--10, 10--50, 50--100 units
1090+
* a single integer (e.g. `10`): data are aggregated over a regular sequence of 10-unit thickness slabs
1091+
* a vector of 2 integers (e.g. `c(50, 60)`): data are aggregated over depths spanning 50--60 units
1092+
* a vector of 3 or more integers (e.g. `c(0, 5, 10, 50, 100)`): data are aggregated over the depths spanning 0--5, 5--10, 10--50, 50--100 units
10931093

10941094
```{r slab, fig.height=4, fig.width=8}
10951095
# aggregate a couple of the horizon-level attributes,
@@ -1226,7 +1226,7 @@ d.gsm.pedons <- data.table::dcast(
12261226
data.table(d.gsm),
12271227
formula = id + top + bottom ~ variable,
12281228
value.var = 'value'
1229-
)
1229+
)
12301230
12311231
# init SPC
12321232
depths(d.gsm.pedons) <- id ~ top + bottom
@@ -1279,17 +1279,9 @@ Calculation of between-profile dissimilarity is performed using `NCSP()` (Numeri
12791279

12801280
See the [function manual page](http://ncss-tech.github.io/aqp/reference/NCSP.html) and [this paper](http://dx.doi.org/10.1016/j.cageo.2012.10.020) for details.
12811281

1282-
```{r setup2, echo=FALSE, results='hide', warning=FALSE}
1283-
# handle sharpshootR dependency of last chunk
1284-
knitr::opts_chunk$set(
1285-
eval = isTRUE(R.version$major >= 4 &&
1286-
try(requireNamespace("sharpshootR", quietly = TRUE), silent = TRUE))
1287-
)
1288-
```
12891282

12901283
```{r fig.height=6, fig.width=10}
12911284
library(cluster)
1292-
library(sharpshootR)
12931285
12941286
# start fresh
12951287
data(sp4)
@@ -1311,25 +1303,29 @@ d.diana <- diana(d)
13111303
# this function is from the sharpshootR package
13121304
# requires some manual adjustments
13131305
par(mar = c(0, 0, 4, 0))
1314-
plotProfileDendrogram(
1315-
sp4,
1316-
d.diana,
1317-
scaling.factor = 0.9,
1318-
y.offset = 5,
1319-
cex.names = 0.7,
1320-
width = 0.3,
1321-
color = 'ex_Ca_to_Mg',
1322-
name.style = 'center-center',
1323-
hz.depths = TRUE,
1324-
depth.axis = FALSE
1325-
)
1306+
1307+
if(requireNamespace('sharpshootR')) {
1308+
sharpshootR::plotProfileDendrogram(
1309+
sp4,
1310+
d.diana,
1311+
scaling.factor = 0.9,
1312+
y.offset = 5,
1313+
cex.names = 0.7,
1314+
width = 0.3,
1315+
color = 'ex_Ca_to_Mg',
1316+
name.style = 'center-center',
1317+
hz.depths = TRUE,
1318+
depth.axis = FALSE
1319+
)
1320+
}
1321+
13261322
```
13271323

13281324
Some additional examples can be found in:
13291325

1330-
* [Pair-Wise Distances by Generalized Horizon Labels](http://ncss-tech.github.io/AQP/aqp/genhz-distance-eval.html)
1331-
* [Competing Soil Series](http://ncss-tech.github.io/AQP/soilDB/competing-series.html)
1332-
* [Soil Profile Distances](http://ncss-tech.github.io/AQP/aqp/aqp-profile-dissimilarity.html)
1326+
* [Pair-Wise Distances by Generalized Horizon Labels](http://ncss-tech.github.io/AQP/aqp/genhz-distance-eval.html)
1327+
* [Competing Soil Series](http://ncss-tech.github.io/AQP/soilDB/competing-series.html)
1328+
* [Soil Profile Distances](http://ncss-tech.github.io/AQP/aqp/aqp-profile-dissimilarity.html)
13331329

13341330
----------------------------
1335-
This document is based on `aqp` version `r utils::packageDescription("aqp", field="Version")`.
1331+
This document is based on `aqp` version `r utils::packageDescription("aqp", field = "Version")`.

0 commit comments

Comments
 (0)