Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions R/CensoredDataSuite.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@
#' 4) Non-Detect
#' 5) Over-Detect
#' 6) Other Condition/Limit Populated
#' If user has not previously run TADA_FlagMeasureQualifierCode, this function will also run that function to
#' add the columns TADA.MeasureQualifierCode.Flag and TADA.MeasureQualifierCode.Def because user-supplied
#' Result Measure Qualifier codes are also used to ID censored results.
#' If user has not previously run TADA_FlagMeasureQualifierCode, this function will also run that
#' function to add the columns TADA.MeasureQualifierCode.Flag and TADA.MeasureQualifierCode.Def
#' because user-supplied Result Measure Qualifier codes are also used to ID censored results.
#'
#' @export
#'
#'

TADA_IDCensoredData <- function(.data) {
# check .data has all of the required columns
Expand All @@ -53,7 +51,7 @@ TADA_IDCensoredData <- function(.data) {
# when the result value is TEXT but there is a specific text value that indicates
# the result is censored (BPQL, BDL, ND)
# and the TADA.DetectionQuantitationLimitMeasure.MeasureValue and unit is populated
# if more are added, they need to be included below as well (line 194)
# if more are added, they need to be included below as well

.data$TADA.ResultMeasureValue <- ifelse(
(.data$ResultMeasureValue == "BPQL" |
Expand Down Expand Up @@ -267,7 +265,8 @@ TADA_IDCensoredData <- function(.data) {
#' information.
#'
#' @param .data A TADA dataframe
#' @param nd_method A text string indicating the type of method used to populate a non-detect (lower limit) data value. Can be set to "multiplier" (default),"randombelowlimit", or "as-is".
#' @param nd_method A text string indicating the type of method used to populate a non-detect
#' (lower limit) data value. Can be set to "multiplier" (default),"randombelowlimit", or "as-is".
#' @param nd_multiplier A number to be multiplied to the LOWER detection limit for each entry to obtain the censored data value. Must be supplied if nd_method = "multiplier". Defaults to 0.5, or half the detection limit.
#' @param od_method A text string indicating the type of method used to populate an over-detect (upper limit) data value. Can be set to "multiplier" or "as-is" (default).
#' @param od_multiplier A number to be multiplied to the UPPER detection limit for each entry to obtain the censored data value. Must be supplied if od_method = "multiplier". Defaults to 0.5, or half the detection limit.
Expand All @@ -288,10 +287,18 @@ TADA_IDCensoredData <- function(.data) {
#' # and in instances where the measurement is non-detect, set the result value
#' # to half of the detection limit value. For over-detect measurements, retain
#' # the detection limit value as the result value as-is.
#' Data_Nutrients_UT_CensoredFlag <- TADA_SimpleCensoredMethods(Data_Nutrients_UT, nd_method = "multiplier", nd_multiplier = 0.5, od_method = "as-is", od_multiplier = "null")
#' Data_Nutrients_UT_CensoredFlag <- TADA_SimpleCensoredMethods(Data_Nutrients_UT,
#' nd_method = "multiplier",
#' nd_multiplier = 0.5,
#' od_method = "as-is",
#' od_multiplier = "null")
#'
#' # Check for agreement between detection condition and detection limit type, and in instances where the measurement is non-detect, set the result value to a random value between 0 and the detection limit value. For over-detect measurements, retain the detection limit value as the result value as-is.
#' Data_Nutrients_UT_CensoredFlag <- TADA_SimpleCensoredMethods(Data_Nutrients_UT, nd_method = "randombelowlimit", nd_multiplier = "null", od_method = "as-is", od_multiplier = "null")
#' Data_Nutrients_UT_CensoredFlag <- TADA_SimpleCensoredMethods(Data_Nutrients_UT,
#' nd_method = "randombelowlimit",
#' nd_multiplier = "null",
#' od_method = "as-is",
#' od_multiplier = "null")
#'
TADA_SimpleCensoredMethods <- function(.data, nd_method = "multiplier", nd_multiplier = 0.5, od_method = "as-is", od_multiplier = "null") {
# check .data has all of the required columns
Expand Down
6 changes: 4 additions & 2 deletions R/DataDiscoveryRetrieval.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@
#' @examples
#' \dontrun{
#' # example for WI
#' tada1 <- TADA_DataRetrieval(statecode = "WI", countycode = "Dane", characteristicName = "Phosphorus")
#' tada1 <- TADA_DataRetrieval(statecode = "WI", countycode = "Dane",
#' characteristicName = "Phosphorus")
#'
#' # example for UT
#' tada2 <- TADA_DataRetrieval(statecode = "UT", characteristicName = c("Ammonia", "Nitrate", "Nitrogen"))
#' tada2 <- TADA_DataRetrieval(statecode = "UT",
#' characteristicName = c("Ammonia", "Nitrate", "Nitrogen"))
#'
#' # example for SC
#' tada3 <- TADA_DataRetrieval(statecode = "SC", countycode = "Abbeville")
Expand Down
15 changes: 8 additions & 7 deletions R/DepthProfile.R
Original file line number Diff line number Diff line change
Expand Up @@ -1074,10 +1074,10 @@ TADA_DepthProfilePlot <- function(.data,

# figure margin
mrg <- list(
l = 50,
l = 50,
r = 50,
b = 100,
t = (25 + (ceiling(nchar(title)/50)) * 25), # top margin is variable based on number of lines in title
b = 100,
t = (25 + (ceiling(nchar(title) / 50)) * 25), # top margin is variable based on number of lines in title
pad = 0
)

Expand Down Expand Up @@ -1113,7 +1113,8 @@ TADA_DepthProfilePlot <- function(.data,
title = list(
text = title,
xref = "paper",
x = 0.5),
x = 0.5
),
plot_bgcolor = "#e5ecf6",
margin = mrg,
legend = list(
Expand Down Expand Up @@ -1358,10 +1359,10 @@ TADA_DepthProfilePlot <- function(.data,
# adjust margins of plot
scatterplot <- scatterplot %>%
plotly::layout(margin = list(
l = 50,
l = 50,
r = 100,
b = 100,
t = (25 + (ceiling(nchar(title)/50)) * 25),
b = 100,
t = (25 + (ceiling(nchar(title) / 50)) * 25),
pad = 0
))

Expand Down
14 changes: 7 additions & 7 deletions R/Figures.R
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ TADA_TwoCharacteristicScatterplot <- function(.data, id_cols = "TADA.ComparableD
showgrid = FALSE, tickcolor = "black"
),
yaxis = list(
title = stringr::str_remove_all(stringr::str_remove_all(
title = stringr::str_remove_all(stringr::str_remove_all(
stringr::str_remove_all(paste0(param1$TADA.CharacteristicName[1], " ", param1$TADA.ResultMeasure.MeasureUnitCode[1]), stringr::fixed(" (NA)")),
stringr::fixed("NA ")
), stringr::fixed(" NA")),
Expand All @@ -930,7 +930,7 @@ TADA_TwoCharacteristicScatterplot <- function(.data, id_cols = "TADA.ComparableD
yaxis2 = list(
side = "right",
overlaying = "y",
title = stringr::str_remove_all(stringr::str_remove_all(
title = stringr::str_remove_all(stringr::str_remove_all(
stringr::str_remove_all(paste0(param2$TADA.CharacteristicName[1], " ", param2$TADA.ResultMeasure.MeasureUnitCode[1]), stringr::fixed(" (NA)")),
stringr::fixed("NA ")
), stringr::fixed(" NA")),
Expand Down Expand Up @@ -958,11 +958,11 @@ TADA_TwoCharacteristicScatterplot <- function(.data, id_cols = "TADA.ComparableD
y = ~TADA.ResultMeasureValue,
name = stringr::str_remove_all(stringr::str_remove_all(
stringr::str_remove_all(paste0(
param1$TADA.ResultSampleFractionText, " ",
param1$TADA.CharacteristicName, " ",
param1$TADA.MethodSpeciationName
), stringr::fixed(" (NA)")),
stringr::fixed("NA ")
param1$TADA.ResultSampleFractionText, " ",
param1$TADA.CharacteristicName, " ",
param1$TADA.MethodSpeciationName
), stringr::fixed(" (NA)")),
stringr::fixed("NA ")
), stringr::fixed(" NA")),
marker = list(
size = 10,
Expand Down
9 changes: 6 additions & 3 deletions R/Filtering.R
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,13 @@ TADA_FieldValuesTable <- function(.data, field = "null", characteristicName = "n
#' @examples
#' data(Data_6Tribes_5y_Harmonized)
#' # Returns data with ONLY surface water results retained and no TADA.UseForAnalysis.Flag column
#' Data_6Tribes_Assessment1 <- TADA_AnalysisDataFilter(Data_6Tribes_5y_Harmonized, clean = TRUE, surface_water = TRUE, ground_water = FALSE, sediment = FALSE)
#' Data_6Tribes_Assessment1 <- TADA_AnalysisDataFilter(Data_6Tribes_5y_Harmonized, clean = TRUE,
#' surface_water = TRUE, ground_water = FALSE, sediment = FALSE)
#'
#' # Returns data frame with ONLY surface water results identified as usable and adds TADA.UseForAnalysis.Flag column.
#' Data_6Tribes_Assessment2 <- TADA_AnalysisDataFilter(Data_6Tribes_5y_Harmonized, clean = FALSE, surface_water = TRUE, ground_water = FALSE, sediment = FALSE)
#' # Returns data frame with ONLY surface water results identified as usable and adds
#' # TADA.UseForAnalysis.Flag column.
#' Data_6Tribes_Assessment2 <- TADA_AnalysisDataFilter(Data_6Tribes_5y_Harmonized, clean = FALSE,
#' surface_water = TRUE, ground_water = FALSE, sediment = FALSE)
#' unique(Data_6Tribes_Assessment2$TADA.UseForAnalysis.Flag)
#'
TADA_AnalysisDataFilter <- function(.data,
Expand Down
2 changes: 1 addition & 1 deletion R/RequiredCols.R
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ TADA_OrderCols <- function(.data) {

#' Get TADA Template
#'
#' This function returns a blank TADA template that can be used as a starting
#' This function returns a blank TADA template that can be used as a starting
#' point to reformat your own custom data set into the TADA format.
#'
#' @return A TADA template with all required columns for the TADA workflow.
Expand Down
Loading