Apply "QC checks" on calculated metrics and station/sample attributes to "flag" samples for the user. Examples include watershed size or total number of individuals. Can have checks for both high and low values. Checks are stored in separate file. For structure see df.checks in example.
qc.checks(df.metrics, df.checks, input.shape = "wide")
Returns a data frame of SampleID checks and results; Pass and Fail.
used reshape2 package
library(readxl)
# Calculate Metrics
df.samps.bugs <- read_excel(system.file("./extdata/Data_Benthos.xlsx"
, package="BioMonTools")
, guess_max = 10^6)
# Columns to keep
myCols <- c("Area_mi2", "SurfaceArea", "Density_m2", "Density_ft2")
# Run Function
myDF <- df.samps.bugs
df.metric.values.bugs <- metric.values(myDF, "bugs", fun.cols2keep=myCols)
#> Updated col class; TOLVAL2 to numeric
#> Joining with `by = join_by(SAMPLEID, INDEX_NAME, INDEX_CLASS)`
# Import Checks
df.checks <- read_excel(system.file("./extdata/MetricFlags.xlsx"
, package="BioMonTools")
, sheet="Flags")
if (FALSE) { # \dontrun{
# View Checks
View(df.checks)
} # }
# Run Function
df.flags <- qc.checks(df.metric.values.bugs, df.checks)
# Summarize Results
table(df.flags[,"CHECKNAME"], df.flags[,"FLAG"], useNA="ifany")
#>
#> FAIL PASS <NA>
#> Low density (ft2) 0 0 94
#> Low density (m2) 0 0 94
#> Ramellogammarus 0 94 0
#> brackish organisms present 0 94 0
#> catchment, Large 0 94 0
#> catchment, small 23 71 0
#> individuals, Large 0 94 0
#> individuals, dominant 02, Large 93 1 0
#> individuals, small 94 0 0
#> surface area, small 10 81 3