From 67287ebcae363a03db0d55004ff5d0e31676f370 Mon Sep 17 00:00:00 2001 From: Ayla Pearson Date: Fri, 30 Dec 2022 15:20:57 -0800 Subject: [PATCH 01/12] Dealing with warning message that the use of .data in tidyselect expressions was deprecated in tidyselect 1.2.0. --- R/calc-limits.R | 6 +++--- R/estimate-variable-values.R | 2 +- R/lookup.R | 6 +++--- R/test-trends.R | 16 ++++++++-------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/R/calc-limits.R b/R/calc-limits.R index 723e4bb..59d245d 100644 --- a/R/calc-limits.R +++ b/R/calc-limits.R @@ -132,7 +132,7 @@ abs_days_diff <- function(x, y) { assign_30day_periods <- function(x, dates) { if (!is.null(dates)) dates <- sort(unique(dates)) - y <- unique(dplyr::select(x, .data$Date)) + y <- unique(dplyr::select(x, "Date")) y <- dplyr::arrange(y, .data$Date) y$Period <- NA @@ -224,9 +224,9 @@ calc_limits_by <- function(x, term, dates, limits, messages) { } if (!is.null(x$DetectionLimit)) { - x <- dplyr::select(x, .data$Date, .data$Variable, .data$Value, .data$UpperLimit, .data$DetectionLimit, .data$Units) + x <- dplyr::select(x, "Date", "Variable", "Value", "UpperLimit", "DetectionLimit", "Units") } else { - x <- dplyr::select(x, .data$Date, .data$Variable, .data$Value, .data$UpperLimit, .data$Units) + x <- dplyr::select(x, "Date", "Variable", "Value", "UpperLimit", "Units") } x } diff --git a/R/estimate-variable-values.R b/R/estimate-variable-values.R index 8e1b9fb..249d705 100644 --- a/R/estimate-variable-values.R +++ b/R/estimate-variable-values.R @@ -66,7 +66,7 @@ estimate_variable_values_by <- function(x, messages) { } # remove working columns - x %<>% dplyr::select(-.data$yday, -.data$day) + x %<>% dplyr::select(-"yday", -"day") } x } diff --git a/R/lookup.R b/R/lookup.R index 3ad4d1f..7bf3ce3 100644 --- a/R/lookup.R +++ b/R/lookup.R @@ -124,11 +124,11 @@ setup_codes <- function() { codes <- wqbc_codes() codes$Date <- as.Date("2000-01-01") codes$Value <- 1 - dplyr::select(codes, .data$Date, .data$Variable, .data$Value, .data$Units) + dplyr::select(codes, "Date", "Variable", "Value", "Units") } tidyup_limits <- function(x) { - x <- dplyr::select(x, .data$Variable, .data$UpperLimit, .data$Units) + x <- dplyr::select(x, "Variable", "UpperLimit", "Units") x$Variable <- factor(x$Variable, levels = lookup_variables()) x$Units <- factor(x$Units, levels = lookup_units()) x <- dplyr::arrange(x, .data$Variable) @@ -139,7 +139,7 @@ add_missing_limits <- function(x, term) { limits <- wqbc_limits() limits <- dplyr::filter(limits, tolower(.data$Term) == tolower(term)) limits <- dplyr::filter(limits, !.data$Variable %in% x$Variable) - limits <- dplyr::select(limits, .data$Variable, .data$Units) + limits <- dplyr::select(limits, "Variable", "Units") if (!nrow(limits)) { return(x) } diff --git a/R/test-trends.R b/R/test-trends.R index 7caa2d8..4b86f9b 100644 --- a/R/test-trends.R +++ b/R/test-trends.R @@ -91,10 +91,10 @@ test_trends <- function(data, breaks = NULL, FUN = "median", messages = getOptio Value = c(1, NA))) # keep only relevant columns - data %<>% dplyr::select(.data$Station, .data$Date, .data$Variable, .data$Value, .data$Units) + data %<>% dplyr::select("Station", "Date", "Variable", "Value", "Units") # nest for analysis - data %<>% tidyr::nest(Data = c(.data$Date, .data$Value)) + data %<>% tidyr::nest(Data = c("Date", "Value")) # fit trends data %<>% dplyr::mutate(Trend = purrr::map(.data$Data, do_test_trends, @@ -102,8 +102,8 @@ test_trends <- function(data, breaks = NULL, FUN = "median", messages = getOptio )) # unnest and return - data %<>% tidyr::unnest(.data$Trend) - data %<>% dplyr::select(-.data$Data) + data %<>% tidyr::unnest("Trend") + data %<>% dplyr::select(-"Data") tibble::as_tibble(data) } @@ -173,10 +173,10 @@ summarise_for_trends <- function(data, breaks = NULL, FUN = "median", Value = c(1, NA))) # keep only relevant columns - data %<>% dplyr::select(.data$Station, .data$Date, .data$Variable, .data$Value, .data$Units) + data %<>% dplyr::select("Station", "Date", "Variable", "Value", "Units") # nest for analysis - data %<>% tidyr::nest(Data = c(.data$Date, .data$Value)) + data %<>% tidyr::nest(Data = c("Date", "Value")) # summarise data %<>% dplyr::mutate(Summary = purrr::map(.data$Data, do_summarise_for_trends, @@ -184,8 +184,8 @@ summarise_for_trends <- function(data, breaks = NULL, FUN = "median", )) # unnest - data %<>% tidyr::unnest(.data$Summary) - data %<>% dplyr::select(-.data$Data) + data %<>% tidyr::unnest("Summary") + data %<>% dplyr::select(-"Data") # gather and return gather_cols <- setdiff(names(data), c("Station", "Variable", "Units", "Year")) From fb6f36923621ec4e5809cf593480a4f5f7c98b75 Mon Sep 17 00:00:00 2001 From: Ayla Pearson Date: Fri, 30 Dec 2022 15:56:02 -0800 Subject: [PATCH 02/12] fixing deprecation warning that aes_string() was deprecated in ggplot2 3.0.0. --- R/plot.R | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/R/plot.R b/R/plot.R index 5067c19..b03a7fd 100644 --- a/R/plot.R +++ b/R/plot.R @@ -12,25 +12,30 @@ plot_timeseries_by <- function(data, title = NULL, y0, size, messages) { if (!is.null(title)) chk_string(title) + # to deal with CMD variable note + Date <- rlang::sym("Date") + Value <- rlang::sym("Value") + Outlier <- rlang::sym("Outlier") + Detected <- rlang::sym("Detected") data %<>% dplyr::mutate(Detected = detected(.data$Value, .data$DetectionLimit)) data$Detected %<>% factor(levels = c(TRUE, FALSE)) data$Outlier %<>% factor(levels = c(TRUE, FALSE)) - gp <- ggplot2::ggplot(data, ggplot2::aes_string(x = "Date", y = "Value")) + gp <- ggplot2::ggplot(data, ggplot2::aes(x = Date, y = Value)) if (!is.null(title)) gp <- gp + ggplot2::ggtitle(title) if (any(!is.na(data$Outlier))) { if (any(!is.na(data$Detected))) { - gp <- gp + ggplot2::geom_point(ggplot2::aes_string(color = "Outlier", alpha = "Detected"), size = size) + gp <- gp + ggplot2::geom_point(ggplot2::aes(color = Outlier, alpha = Detected), size = size) } else { - gp <- gp + ggplot2::geom_point(ggplot2::aes_string(color = "Outlier"), size = size) + gp <- gp + ggplot2::geom_point(ggplot2::aes(color = Outlier), size = size) } } else { if (any(!is.na(data$Detected))) { - gp <- gp + ggplot2::geom_point(ggplot2::aes_string(alpha = "Detected"), size = size) + gp <- gp + ggplot2::geom_point(ggplot2::aes(alpha = Detected), size = size) } else { gp <- gp + ggplot2::geom_point(size = size) } From fd97e48d9e1cbe53f46903af0834f08aa16910cf Mon Sep 17 00:00:00 2001 From: Ayla Pearson Date: Fri, 30 Dec 2022 15:56:24 -0800 Subject: [PATCH 03/12] updating roxygen version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 878239c..0651f76 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -51,7 +51,7 @@ Remotes: bcgov/rems, bcgov/canwqdata VignetteBuilder: knitr -RoxygenNote: 7.1.1 +RoxygenNote: 7.2.3 Roxygen: list(markdown = TRUE) Encoding: UTF-8 RdMacros: lifecycle From f13c293c9a618b44083927fdb9eafabc48e28ee1 Mon Sep 17 00:00:00 2001 From: Ayla Pearson Date: Fri, 30 Dec 2022 15:56:31 -0800 Subject: [PATCH 04/12] updating docs --- man/wqbc-package.Rd | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/man/wqbc-package.Rd b/man/wqbc-package.Rd index b59ece7..eedac8f 100644 --- a/man/wqbc-package.Rd +++ b/man/wqbc-package.Rd @@ -6,8 +6,7 @@ \alias{wqbc-package} \title{wqbc: Tidy Water Quality Data and Calculate Thresholds for British Columbia} \description{ -Tidies water quality data and calculates water quality thresholds - for British Columbia. +Tidies water quality data and calculates water quality thresholds for British Columbia. } \seealso{ Useful links: From e7ecf63218b05dc9f5dd18d18e205f1c1d6c5cb5 Mon Sep 17 00:00:00 2001 From: Ayla Pearson Date: Fri, 30 Dec 2022 16:06:51 -0800 Subject: [PATCH 05/12] fixing deprecation warning for using an external vector in selections was deprecated in tidyselect 1.1.0. --- R/test-trends.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/test-trends.R b/R/test-trends.R index 4b86f9b..6383dba 100644 --- a/R/test-trends.R +++ b/R/test-trends.R @@ -189,5 +189,5 @@ summarise_for_trends <- function(data, breaks = NULL, FUN = "median", # gather and return gather_cols <- setdiff(names(data), c("Station", "Variable", "Units", "Year")) - data %>% tidyr::pivot_longer(gather_cols, names_to = "Month", values_to = "Value") + data %>% tidyr::pivot_longer(tidyr::all_of(gather_cols), names_to = "Month", values_to = "Value") } From 8e6754f1e4d1f845b6194eed7c66b2a8ba59c2c0 Mon Sep 17 00:00:00 2001 From: Ayla Pearson Date: Fri, 30 Dec 2022 16:56:46 -0800 Subject: [PATCH 06/12] fixing chkor deprecation error --- R/calc-limits.R | 4 ++-- R/clean-wqdata.R | 2 +- R/codes.R | 6 ++++-- R/estimate-variable-values.R | 2 +- R/lookup.R | 10 +++++----- R/plot.R | 3 +-- R/substitute.R | 5 +++-- 7 files changed, 17 insertions(+), 15 deletions(-) diff --git a/R/calc-limits.R b/R/calc-limits.R index 59d245d..587852f 100644 --- a/R/calc-limits.R +++ b/R/calc-limits.R @@ -292,10 +292,10 @@ calc_limits <- function(x, by = NULL, term = "long", dates = NULL, keep_limits = messages = getOption("wqbc.messages", default = TRUE), use = "Freshwater Life") { chk_data(x) - chkor(chk_null(by), check_values(by, "")) + chk_null_or(by, vld = vld_character) chk_string(term) chk_subset(term, c("long", "short", "long-daily")) - chkor(chk_null(dates), check_values(dates, Sys.Date())) + chk_null_or(dates, vld = vld_date) chk_flag(keep_limits) chk_flag(delete_outliers) chk_flag(estimate_variables) diff --git a/R/clean-wqdata.R b/R/clean-wqdata.R index 2df47c2..bbb87e9 100644 --- a/R/clean-wqdata.R +++ b/R/clean-wqdata.R @@ -109,7 +109,7 @@ clean_wqdata <- function(x, by = NULL, max_cv = Inf, FUN = mean) { chk_data(x) - chkor(chk_null(by), check_values(by, "")) + chk_null_or(by, vld = vld_character) chk_number(max_cv) check_values(messages, TRUE) diff --git a/R/codes.R b/R/codes.R index fefe431..83f7388 100644 --- a/R/codes.R +++ b/R/codes.R @@ -33,7 +33,8 @@ wqbc_codes <- function(compress = FALSE) { #' @seealso \code{\link{expand_ems_codes}} #' @export compress_ems_codes <- function(x) { - chkor(chk_character(x), chk_s3_class(x, "factor")) + + chkor_vld(vld_character(x), vld_s3_class(x, "factor")) x <- as.character(x) x <- gsub("[_]", "-", x) @@ -52,7 +53,8 @@ compress_ems_codes <- function(x) { #' @seealso \code{\link{compress_ems_codes}} #' @export expand_ems_codes <- function(x) { - chkor(chk_character(x), chk_s3_class(x, "factor")) + + chkor_vld(vld_character(x), vld_s3_class(x, "factor")) x <- as.character(x) x <- gsub("[-]", "_", x) diff --git a/R/estimate-variable-values.R b/R/estimate-variable-values.R index 249d705..d88976f 100644 --- a/R/estimate-variable-values.R +++ b/R/estimate-variable-values.R @@ -74,7 +74,7 @@ estimate_variable_values_by <- function(x, messages) { estimate_variable_values <- function(data, by = NULL, variables = estimated_variables(), messages = getOption("wqbc.messages", default = TRUE)) { check_data(data, values = list(Date = Sys.Date(), Variable = "", Value = c(1, NA), Units = "")) - chkor(chk_null(by), check_values(by, "")) + chk_null_or(by, vld = vld_character) check_values(variables, "") if (!all(variables %in% estimated_variables())) error("Unrecognized variables") chk_flag(messages) diff --git a/R/lookup.R b/R/lookup.R index 7bf3ce3..bed67d2 100644 --- a/R/lookup.R +++ b/R/lookup.R @@ -92,7 +92,7 @@ lookup_variables <- function( return(wqbc_codes()$Variable) } - chkor(chk_character(codes), chk_s3_class(codes, "factor")) + chkor_vld(vld_character(codes), vld_s3_class(codes, "factor")) codes <- as.character(codes) codes <- compress_ems_codes(codes) d <- dplyr::left_join(data.frame(Code = codes, stringsAsFactors = FALSE), @@ -169,10 +169,10 @@ add_missing_limits <- function(x, term) { lookup_limits <- function(ph = NULL, hardness = NULL, chloride = NULL, methyl_mercury = NULL, term = "long", use = "Freshwater Life") { - chkor(chk_null(ph), check_values(ph, 1)) - chkor(chk_null(hardness), check_values(hardness, 1)) - chkor(chk_null(chloride), check_values(chloride, 1)) - chkor(chk_null(methyl_mercury), check_values(methyl_mercury, 1)) + chk_null_or(ph, vld = vld_double) + chk_null_or(hardness, vld = vld_double) + chk_null_or(chloride, vld = vld_double) + chk_null_or(methyl_mercury, vld = vld_double) chk_string(term) term <- tolower(term) diff --git a/R/plot.R b/R/plot.R index b03a7fd..84f5b08 100644 --- a/R/plot.R +++ b/R/plot.R @@ -74,8 +74,7 @@ plot_timeseries_fun <- function(data, by, y0, size, messages) { #' plot_timeseries(ccme, by = "Variable") plot_timeseries <- function(data, by = NULL, y0 = TRUE, size = 1, messages = getOption("wqbc.messages", default = TRUE)) { - chkor(chk_null(by), check_values(by, "")) - + chk_null_or(by, vld = vld_character) chk_flag(y0) chk_flag(messages) diff --git a/R/substitute.R b/R/substitute.R index 256ec4a..54c3f50 100644 --- a/R/substitute.R +++ b/R/substitute.R @@ -96,7 +96,8 @@ wqbc_substitute <- function(org, mod = org, sub, sub_mod = sub, messages) { #' @export substitute_units <- function( x, messages = getOption("wqbc.messages", default = TRUE)) { - chkor(chk_character(x), chk_s3_class(x, "factor")) + + chkor_vld(vld_character(x), vld_s3_class(x, "factor")) check_values(messages, TRUE) x <- as.character(x) @@ -140,7 +141,7 @@ substitute_units <- function( substitute_variables <- function( x, strict = TRUE, messages = getOption("wqbc.messages", default = TRUE)) { - chkor(chk_character(x), chk_s3_class(x, "factor")) + chkor_vld(vld_character(x), vld_s3_class(x, "factor")) check_values(strict, TRUE) check_values(messages, TRUE) From 6c0866bdadd976c72f979f729ce73d7d2c98b5d4 Mon Sep 17 00:00:00 2001 From: Ayla Pearson Date: Fri, 30 Dec 2022 19:14:11 -0800 Subject: [PATCH 07/12] adding error handling to create NA's instead of throwing an error --- R/summarise-wqdata.R | 48 +++++++++++++++++++++++++++++--------------- R/utils.R | 2 ++ 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/R/summarise-wqdata.R b/R/summarise-wqdata.R index ad131fc..608506d 100644 --- a/R/summarise-wqdata.R +++ b/R/summarise-wqdata.R @@ -77,24 +77,40 @@ summarise_wqdata_by <- function(x, censored, na.rm, conf_level, quan_range) { if(any(x$Value == 0)) { return(summarise_zero_values(x, censored)) } - ml <- with(x, cenmle(Value, Censored, dist = "lognormal", conf.int = conf_level)) - est <- mean(ml) - quantiles <- quantile(ml, c((1-quan_range)/2, quan_range + (1-quan_range)/2)) + ml <- with(x, cenmle(Value, Censored, dist = "lognormal", conf.int = conf_level)) + est <- try(mean(ml), silent = TRUE) - tibble::tibble( - n = nrow(x), - ncen = sum(x$Censored), - min = min, - max = max, - mean = est[["mean"]], - median = median(ml), - lowerQ = quantiles[[1]], - upperQ = quantiles[[2]], - sd = sd(ml), - se = est[["se"]], - lowerCL = est[[3]], - upperCL = est[[4]]) + if (!is_try_error(est)) { + quantiles <- quantile(ml, c((1-quan_range)/2, quan_range + (1-quan_range)/2)) + tibble::tibble( + n = nrow(x), + ncen = sum(x$Censored), + min = min, + max = max, + mean = est[["mean"]], + median = median(ml), + lowerQ = quantiles[[1]], + upperQ = quantiles[[2]], + sd = sd(ml), + se = est[["se"]], + lowerCL = est[[3]], + upperCL = est[[4]]) + } else { + tibble::tibble( + n = nrow(x), + ncen = sum(x$Censored), + min = min, + max = max, + mean = NA_real_, + median = NA_real_, + lowerQ = NA_real_, + upperQ = NA_real_, + sd = NA_real_, + se = NA_real_, + lowerCL = NA_real_, + upperCL = NA_real_) + } } summarise_wqdata_norows <- function(x, by) { diff --git a/R/utils.R b/R/utils.R index 51408b1..e6db937 100644 --- a/R/utils.R +++ b/R/utils.R @@ -129,3 +129,5 @@ is_color <- function(x) { } vapply(x, fun, TRUE) } + +is_try_error <- function(x) inherits(x, "try-error") From 6c0cd1eb132e7f74ffa2cbfdb7cd4b49997c0db6 Mon Sep 17 00:00:00 2001 From: Ayla Pearson Date: Fri, 30 Dec 2022 19:39:34 -0800 Subject: [PATCH 08/12] clean up --- R/summarise-wqdata.R | 2 -- 1 file changed, 2 deletions(-) diff --git a/R/summarise-wqdata.R b/R/summarise-wqdata.R index 608506d..7ffcc2e 100644 --- a/R/summarise-wqdata.R +++ b/R/summarise-wqdata.R @@ -63,7 +63,6 @@ summarise_wqdata_by <- function(x, censored, na.rm, conf_level, quan_range) { if(any(is.na(x$Value))) { return(summarise_missing_values(x, censored)) } - # get min and max before censored values altered min <- min(x$Value) max <- max(x$Value) @@ -77,7 +76,6 @@ summarise_wqdata_by <- function(x, censored, na.rm, conf_level, quan_range) { if(any(x$Value == 0)) { return(summarise_zero_values(x, censored)) } - ml <- with(x, cenmle(Value, Censored, dist = "lognormal", conf.int = conf_level)) est <- try(mean(ml), silent = TRUE) From 0f93f0ac4c1b387cf62e01f6558afc7e72da76cf Mon Sep 17 00:00:00 2001 From: Ayla Pearson Date: Fri, 30 Dec 2022 19:39:55 -0800 Subject: [PATCH 09/12] cleaning up warning messages in tests --- tests/testthat/test-summarise-wqdata.R | 51 +++++++++++++++++++++----- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/tests/testthat/test-summarise-wqdata.R b/tests/testthat/test-summarise-wqdata.R index 1868682..45b5174 100644 --- a/tests/testthat/test-summarise-wqdata.R +++ b/tests/testthat/test-summarise-wqdata.R @@ -100,8 +100,26 @@ test_that("some missing values uncensored", { }) test_that("na.rm = TRUE with only 1 non-missing value", { - x <- summarise_wqdata(data.frame(Variable = "1", Value = c(NA_real_, 1), stringsAsFactors = FALSE), - na.rm = TRUE) + x <- suppressWarnings( + summarise_wqdata( + data.frame( + Variable = "1", + Value = c(NA_real_, 1), + stringsAsFactors = FALSE + ), + na.rm = TRUE + ) + ) + expect_warning( + summarise_wqdata( + data.frame( + Variable = "1", + Value = c(NA_real_, 1), + stringsAsFactors = FALSE + ), + na.rm = TRUE + ) + ) y <- tibble::tibble(Variable = "1", n = 1L, ncen = 0L, min = 1, max = 1, mean = NA_real_, median = NA_real_, lowerQ = NA_real_, upperQ = NA_real_, sd = NA_real_, se = NA_real_, lowerCL = NA_real_, upperCL = NA_real_) @@ -109,13 +127,28 @@ test_that("na.rm = TRUE with only 1 non-missing value", { }) test_that("multiple variables each with 1 value", { - x <- summarise_wqdata(data.frame(Variable = c("1", "three"), Value = c(1, 3), stringsAsFactors = FALSE)) - y <- tibble::tibble(Variable = c("1", "three"), n = c(1L, 1L), ncen = c(0L, -0L), min = c(1, 3), max = c(1, 3), mean = c(NA_real_, NA_real_ -), median = c(NA_real_, NA_real_), lowerQ = c(NA_real_, NA_real_ -), upperQ = c(NA_real_, NA_real_), sd = c(NA_real_, NA_real_), - se = c(NA_real_, NA_real_), lowerCL = c(NA_real_, NA_real_ - ), upperCL = c(NA_real_, NA_real_)) + expect_warning( + summarise_wqdata( + data.frame( + Variable = c("1", "three"), Value = c(1, 3), stringsAsFactors = FALSE + ) + ) + ) + + x <- suppressWarnings( + summarise_wqdata( + data.frame( + Variable = c("1", "three"), Value = c(1, 3), stringsAsFactors = FALSE + ) + ) + ) + + y <- tibble::tibble( + Variable = c("1", "three"), n = c(1L, 1L), ncen = c(0L, 0L), min = c(1, 3), + max = c(1, 3), mean = c(NA_real_, NA_real_), median = c(NA_real_, NA_real_), + lowerQ = c(NA_real_, NA_real_), upperQ = c(NA_real_, NA_real_), + sd = c(NA_real_, NA_real_), se = c(NA_real_, NA_real_), + lowerCL = c(NA_real_, NA_real_), upperCL = c(NA_real_, NA_real_)) expect_equal(as.data.frame(x), as.data.frame(y)) }) From ba302191783511b7ad398fbdacd6379d72a54c34 Mon Sep 17 00:00:00 2001 From: Ayla Pearson Date: Fri, 30 Dec 2022 19:59:24 -0800 Subject: [PATCH 10/12] adding warning handling to testing to clean up test results --- tests/testthat/test-tidy-data.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-tidy-data.R b/tests/testthat/test-tidy-data.R index ebe9ce2..983648e 100644 --- a/tests/testthat/test-tidy-data.R +++ b/tests/testthat/test-tidy-data.R @@ -249,10 +249,11 @@ test_that("tidy_ec_data works", { "SITE_NO", "DateTime", "Variable", "Code", "Value", "Units", "DetectionLimit", "ResultLetter" ) - tidied_ec <- tidy_ec_data(test_ec) + expect_warning(tidy_ec_data(test_ec)) + tidied_ec <- suppressWarnings(tidy_ec_data(test_ec)) expect_is(tidied_ec, "ec_tidy") expect_equal(names(tidied_ec), default_ec_names) - tidied_ec <- tidy_ec_data(test_ec, cols = "STATUS_STATUT") + tidied_ec <- suppressWarnings(tidy_ec_data(test_ec, cols = "STATUS_STATUT")) expect_equal(names(tidied_ec), c(default_ec_names, "STATUS_STATUT")) }) From 5b4265d03bb1fdffb26692218d9871683c09e7d8 Mon Sep 17 00:00:00 2001 From: Ayla Pearson Date: Mon, 2 Jan 2023 10:22:13 -0800 Subject: [PATCH 11/12] switching methods to .data$var_name from using rlang sym(var_name) in ggplot aes function calls --- R/plot.R | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/R/plot.R b/R/plot.R index 84f5b08..59324b0 100644 --- a/R/plot.R +++ b/R/plot.R @@ -12,30 +12,25 @@ plot_timeseries_by <- function(data, title = NULL, y0, size, messages) { if (!is.null(title)) chk_string(title) - # to deal with CMD variable note - Date <- rlang::sym("Date") - Value <- rlang::sym("Value") - Outlier <- rlang::sym("Outlier") - Detected <- rlang::sym("Detected") data %<>% dplyr::mutate(Detected = detected(.data$Value, .data$DetectionLimit)) data$Detected %<>% factor(levels = c(TRUE, FALSE)) data$Outlier %<>% factor(levels = c(TRUE, FALSE)) - gp <- ggplot2::ggplot(data, ggplot2::aes(x = Date, y = Value)) + gp <- ggplot2::ggplot(data, ggplot2::aes(x = .data$Date, y = .data$Value)) if (!is.null(title)) gp <- gp + ggplot2::ggtitle(title) if (any(!is.na(data$Outlier))) { if (any(!is.na(data$Detected))) { - gp <- gp + ggplot2::geom_point(ggplot2::aes(color = Outlier, alpha = Detected), size = size) + gp <- gp + ggplot2::geom_point(ggplot2::aes(color = .data$Outlier, alpha = .data$Detected), size = size) } else { - gp <- gp + ggplot2::geom_point(ggplot2::aes(color = Outlier), size = size) + gp <- gp + ggplot2::geom_point(ggplot2::aes(color = .data$Outlier), size = size) } } else { if (any(!is.na(data$Detected))) { - gp <- gp + ggplot2::geom_point(ggplot2::aes(alpha = Detected), size = size) + gp <- gp + ggplot2::geom_point(ggplot2::aes(alpha = .data$Detected), size = size) } else { gp <- gp + ggplot2::geom_point(size = size) } From c69ce879522f20035d1211fcb90a6949357d7dde Mon Sep 17 00:00:00 2001 From: Ayla Pearson Date: Tue, 3 Jan 2023 14:10:47 -0800 Subject: [PATCH 12/12] - `summarise_wqdata()` now returns missing values instead of throwing an error when unable to calculate summary statistics using log-normal maximum-likelihood models. --- DESCRIPTION | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0651f76..0e79059 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -3,14 +3,18 @@ Type: Package Title: Tidy Water Quality Data and Calculate Thresholds for British Columbia Version: 0.3.1.9003 Authors@R: c( - person("Joe", "Thorley", , "joe@poissonconsulting.ca", c("aut", "ctr"), comment = c(ORCID = "0000-0002-7683-4592")), - person("Colin", "Millar", , "colinpmillar@gmail.com", c("aut", "ctr")), - person("Andy", "Teucher", , "andy.teucher@gov.bc.ca", c("aut", "cre")), - person("Sebastian", "Dalgarno", , "seb@poissonconsulting.ca", "ctb", comment = c(ORCID = "0000-0002-3658-4517")), - person("Wendy", "Wang", role = c("ctb", "ctr")), - person("Stephanie", "Hazlitt", , "stephanie.hazlitt@gov.bc.ca", "ctb"), - person("Robyn", "Irvine", role = c("ctb", "ctr")), - person("Province of British Columbia", role = "cph") + person("Joe", "Thorley", , "joe@poissonconsulting.ca", role = c("aut", "ctr"), + comment = c(ORCID = "0000-0002-7683-4592")), + person("Colin", "Millar", , "colinpmillar@gmail.com", role = c("aut", "ctr")), + person("Andy", "Teucher", , "andy.teucher@gov.bc.ca", role = c("aut", "cre")), + person("Sebastian", "Dalgarno", , "seb@poissonconsulting.ca", role = "ctb", + comment = c(ORCID = "0000-0002-3658-4517")), + person("Wendy", "Wang", role = c("ctb", "ctr")), + person("Stephanie", "Hazlitt", , "stephanie.hazlitt@gov.bc.ca", role = "ctb"), + person("Robyn", "Irvine", role = c("ctb", "ctr")), + person("Province of British Columbia", role = "cph"), + person("Ayla", "Pearson", , "ayla@poissonconsulting.ca", role = "ctb", + comment = c(ORCID = "0000-0001-7388-1222")) ) Description: Tidies water quality data and calculates water quality thresholds for British Columbia.