Skip to contents

Function checks the validity of each characteristic-method speciation combination in the dataframe. When clean = "invalid_only", rows with invalid characteristic-method speciation combinations are removed. Default is clean = "invalid_only". When flaggedonly = TRUE, dataframe is filtered to show only rows with "Invalid" or "NonStandardized" characteristic-method speciation combinations. Default is flaggedonly = FALSE.

Usage

TADA_FlagSpeciation(
  .data,
  clean = c("invalid_only", "nonstandardized_only", "both", "none"),
  flaggedonly = FALSE
)

Arguments

.data

TADA dataframe

clean

Character argument with options "invalid_only", "nonstandardized_only", "both", or "none." The default is clean = "invalid_only" which removes rows of data flagged as having "Invalid" characteristic-method speciation combinations. When clean = "nonstandardized_only", the function removes rows of data flagged as having "NonStandardized" characteristic-method speciation combinations. When clean = "both", the function removes rows of data flagged as either "Invalid" or "NonStandardized". And when clean = "none", the function does not remove any "Invalid" or "NonStandardized" rows of data.

flaggedonly

Boolean argument; filters to show only the "Invalid" characteristic-method speciation combinations from the dataframe when flaggedonly = TRUE. Default is flaggedonly = FALSE.

Value

This function adds TADA.MethodSpeciation.Flag to the dataframe. This column flags each TADA.CharacteristicName and MethodSpeciationName combination in your dataframe as either "NonStandardized", "Invalid", "Valid", or "Not Reviewed". When clean = "none" and flaggedonly = TRUE, the dataframe is filtered to show only the "Invalid" and "NonStandardized data; the column TADA.MethodSpeciation.Flag is still appended. When clean = "invalid_only" and flaggedonly = FALSE, "Invalid" rows are removed from the dataframe, but "NonStandardized" rows are retained. When clean = "nonstandardized_only" and flaggedonly = FALSE, "NonStandardized" rows are removed, but "Invalid" rows are retained. The default is clean = "invalid_only" and flaggedonly = FALSE.

Details

The “Not Reviewed” value within "TADA.ResultAboveUpperThreshold.Flag" means that the EPA WQX team has not yet reviewed the combinations (see https://cdx.epa.gov/wqx/download/DomainValues/QAQCCharacteristicValidation.CSV). The WQX team plans to review and update these new combinations quarterly.

Examples

# Load example dataset:
data(Data_Nutrients_UT)

# Remove data with invalid characteristic-method speciation combinations from dataframe,
# but retain "NonStandardized" combinations flagged in new column 'TADA.MethodSpeciation.Flag':
InvalidSpeciation_clean <- TADA_FlagSpeciation(Data_Nutrients_UT)

# Remove data with "NonStandardized" characteristic-method speciation combinations
# from dataframe but retain invalid combinations flagged in new column 'TADA.MethodSpeciation.Flag':
NonstandardSpeciation_clean <- TADA_FlagSpeciation(Data_Nutrients_UT, clean = "nonstandardized_only")
#> Warning: There was 1 warning in `dplyr::filter()`.
#>  In argument: `!=...`.
#> Caused by warning in `TADA.MethodSpeciation.Flag != c("NonStandardized", "Nonstandardized",
#>     "Non Standardized")`:
#> ! longer object length is not a multiple of shorter object length

# Remove both "Invalid" and "NonStandardized" characteristic-method speciation combinations
# from dataframe:
Speciation_clean <- TADA_FlagSpeciation(Data_Nutrients_UT, clean = "both")

# Flag, but do not remove, data with "Invalid" or "NonStandardized" characteristic-method speciation
# combinations in new column titled "TADA.MethodSpeciation.Flag":
InvalidSpeciation_flags <- TADA_FlagSpeciation(Data_Nutrients_UT, clean = "none")
#> [1] "Rows with invalid speciations have been flagged but retained. Review these rows before proceeding and/or set clean = 'invalid_only' or 'both'."

# Show only invalid characteristic-method speciation combinations:
InvalidSpeciation_flaggedonly <- TADA_FlagSpeciation(Data_Nutrients_UT, clean = "nonstandardized_only", flaggedonly = TRUE)
#> Warning: There was 1 warning in `dplyr::filter()`.
#>  In argument: `!=...`.
#> Caused by warning in `TADA.MethodSpeciation.Flag != c("NonStandardized", "Nonstandardized",
#>     "Non Standardized")`:
#> ! longer object length is not a multiple of shorter object length
#> Warning: There was 1 warning in `dplyr::filter()`.
#>  In argument: `!=...`.
#> Caused by warning in `TADA.MethodSpeciation.Flag != c("Not Reviewed", "Accepted", "Y", "Valid")`:
#> ! longer object length is not a multiple of shorter object length

# Show only "NonStandardized" characteristic-method speciation combinations:
NonstandardSpeciation_flaggedonly <- TADA_FlagSpeciation(Data_Nutrients_UT, clean = "invalid_only", flaggedonly = TRUE)
#> Warning: There was 1 warning in `dplyr::filter()`.
#>  In argument: `!=...`.
#> Caused by warning in `TADA.MethodSpeciation.Flag != c("Not Reviewed", "Accepted", "Y", "Valid")`:
#> ! longer object length is not a multiple of shorter object length