test_hz_logic {aqp} | R Documentation |
Simple tests for horizon logic, based on a simple data.frame of ordered horizons.
test_hz_logic(i, topcol, bottomcol, strict = FALSE)
i |
a data.frame associated with a single soil profile, ordered by depth |
topcol |
character, giving the name of the column in |
bottomcol |
character, giving the name of the column in |
strict |
logical, should continuity tests be performed– i.e. for non-contiguous horizon boundaries |
By default, this function tests for NA and overlapping horizons. If any either are encountered, FALSE is returned.
logical: TRUE –> pass, FALSE –> fail
D.E. Beaudette
http://casoilresource.lawr.ucdavis.edu/
## simple example: just one profile
data(sp1)
depths(sp1) <- id ~ top + bottom
s <- horizons(sp1[1, ])
## check
# fails due to missing hz boundary
s$bottom[6] <- NA # missing horizon boundary, common on bottom-most hz
test_hz_logic(s, 'top', 'bottom', strict=FALSE)
## hz_logic_pass
## FALSE
# fails due to inconsistent hz boundary
s$bottom[3] <- 30 # inconsistent hz boundary
test_hz_logic(s, 'top', 'bottom', strict=TRUE)
## hz_logic_pass
## FALSE
## filtering bad data
## Not run:
##D # missing bottom horizons
##D x$hzn_bot[!is.na(x$hzn_top) & is.na(x$hzn_bot)] <- x$hzn_top[!is.na(x$hzn_top) & is.na(x$hzn_bot)]
##D
##D # remove O horizons where top > bottom
##D bad.O.hz.idx <- which(x$hzn_top > x$hzn_bot)
##D if(length(bad.O.hz.idx) > 0)
##D x <- x[-bad.O.hz.idx, ]
## End(Not run)
## checking for bad data: do this before promoting to SoilProfileCollection object
library(plyr)
data(sp1)
# horizon logic can be tested via data.frame, at 2 levels of scrutiny:
ddply(sp1, 'id', test_hz_logic, topcol='top', bottomcol='bottom', strict=FALSE)
## id hz_logic_pass
## 1 P001 TRUE
## 2 P002 TRUE
## 3 P003 TRUE
## 4 P004 TRUE
## 5 P005 TRUE
## 6 P006 TRUE
## 7 P007 TRUE
## 8 P008 TRUE
## 9 P009 TRUE
ddply(sp1, 'id', test_hz_logic, topcol='top', bottomcol='bottom', strict=TRUE)
## id hz_logic_pass
## 1 P001 TRUE
## 2 P002 TRUE
## 3 P003 TRUE
## 4 P004 TRUE
## 5 P005 TRUE
## 6 P006 TRUE
## 7 P007 TRUE
## 8 P008 TRUE
## 9 P009 TRUE