Learn R Programming

aqp (version 1.18)

test_hz_logic: Test Horizon Logic

Description

Simple tests for horizon logic, based on a simple data.frame of ordered horizons.

Usage

test_hz_logic(i, topcol, bottomcol, strict = FALSE)

Arguments

i

a data.frame associated with a single soil profile, ordered by depth

topcol

character, giving the name of the column in i that describes horizon top depth

bottomcol

character, giving the name of the column in i that describes horizon bottom depth

strict

logical, should continuity tests be performed-- i.e. for non-contiguous horizon boundaries

Value

logical: TRUE --> pass, FALSE --> fail

Details

By default, this function tests for NA and overlapping horizons. If any either are encountered, FALSE is returned.

References

http://casoilresource.lawr.ucdavis.edu/

See Also

depths<-

Examples

Run this code
# NOT RUN {
## 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)

# fails due to inconsistent hz boundary
s$bottom[3] <- 30 # inconsistent hz boundary
test_hz_logic(s, 'top', 'bottom', strict=TRUE)


## filtering bad data 
# }
# NOT RUN {
# missing bottom horizons
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)]

# remove O horizons where top > bottom
bad.O.hz.idx <- which(x$hzn_top > x$hzn_bot)
if(length(bad.O.hz.idx) > 0)
	x <- x[-bad.O.hz.idx, ]
# }
# 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)
ddply(sp1, 'id', test_hz_logic, topcol='top', bottomcol='bottom', strict=TRUE)
# }

Run the code above in your browser using DataLab