From 580256f54fb158b20f1f41cbf1a86f00e7e9138c Mon Sep 17 00:00:00 2001 From: CJ Yetman Date: Wed, 13 Nov 2024 10:41:08 +0100 Subject: [PATCH] fix assert naming --- R/plot_sankey.R | 2 +- R/plot_scatter.R | 2 +- R/prep_sankey.R | 8 ++++---- R/prep_scatter.R | 10 +++++----- R/utils.R | 10 +++++----- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/R/plot_sankey.R b/R/plot_sankey.R index 0d26e90a..5036039c 100644 --- a/R/plot_sankey.R +++ b/R/plot_sankey.R @@ -167,7 +167,7 @@ check_plot_sankey <- function(data, group_var, capitalise_node_labels) { crucial_names <- c(group_var, "middle_node", "is_aligned", "loan_size_outstanding") - assert_missing_names(data, crucial_names) + assert_no_missing_names(data, crucial_names) if (!is.logical(capitalise_node_labels)) { cli::cli_abort(c( x = "`capitalise_node_labels` must have a {.cls logical} value.", diff --git a/R/plot_scatter.R b/R/plot_scatter.R index 1c9efec5..081a3010 100644 --- a/R/plot_scatter.R +++ b/R/plot_scatter.R @@ -211,7 +211,7 @@ plot_scatter <- function(data, check_plot_scatter <- function(data, alignment_limit, cap_outliers, floor_outliers) { - assert_missing_names(data, c( + assert_no_missing_names(data, c( "name", "buildout", "phaseout", "net" )) diff --git a/R/prep_sankey.R b/R/prep_sankey.R index fb89e930..8dd28ba9 100644 --- a/R/prep_sankey.R +++ b/R/prep_sankey.R @@ -92,7 +92,7 @@ check_prep_sankey <- function(data_alignment, middle_node2) { names_all <- c(group_var, "name_abcd", "sector") names_aggergate <- c("region", "year") - assert_missing_names(data_alignment, c(names_all, names_aggergate)) + assert_no_missing_names(data_alignment, c(names_all, names_aggergate)) if (!(region %in% unique(data_alignment$region))) { cli::cli_abort(c( x = "{.arg region} value not found in {.var data_alignment} dataset", @@ -110,13 +110,13 @@ check_prep_sankey <- function(data_alignment, i = "the value{?s} in {.arg year} {?is/are}: {.val {unique(year)}}" )) } - assert_middle_node_column_not_found(data_alignment, middle_node, env = list(data = substitute(data_alignment))) + assert_middle_node_column_exists(data_alignment, middle_node, env = list(data = substitute(data_alignment))) if (!is.null(middle_node2)) { - assert_middle_node_column_not_found(data_alignment, middle_node2, list(data = substitute(data_alignment))) + assert_middle_node_column_exists(data_alignment, middle_node2, list(data = substitute(data_alignment))) } } -assert_middle_node_column_not_found <- function(data, name, env = parent.frame()) { +assert_middle_node_column_exists <- function(data, name, env = parent.frame()) { .data <- deparse1(substitute(data, env = env)) if (!(name %in% names(data))) { diff --git a/R/prep_scatter.R b/R/prep_scatter.R index 9b859a8c..6829fde7 100644 --- a/R/prep_scatter.R +++ b/R/prep_scatter.R @@ -96,7 +96,7 @@ check_prep_scatter <- function(data, groups_to_plot, name_col, value_col) { - assert_missing_names( + assert_no_missing_names( data, c( group_var, @@ -108,8 +108,8 @@ check_prep_scatter <- function(data, value_col ) ) - assert_unknown_values(sector, data, "sector") - assert_unknown_values(region, data, "region") - assert_unknown_values(year, data, "year") - assert_unknown_values(groups_to_plot, data, group_var) + assert_no_unknown_values(sector, data, "sector") + assert_no_unknown_values(region, data, "region") + assert_no_unknown_values(year, data, "year") + assert_no_unknown_values(groups_to_plot, data, group_var) } diff --git a/R/utils.R b/R/utils.R index c874643a..580ddfc7 100644 --- a/R/utils.R +++ b/R/utils.R @@ -7,7 +7,7 @@ beautify_scenario_label <- function(label) { #' Check if a named object contains expected names #' -#' Based on fgeo.tool::assert_missing_names() +#' Based on fgeo.tool::abort_if_missing_names() #' #' @param x A named object. #' @param expected_names String; expected names of `x`. @@ -16,12 +16,12 @@ beautify_scenario_label <- function(label) { #' #' @examples #' x <- c(a = 1) -#' assert_missing_names(x, "a") -#' try(assert_missing_names(x, "bad")) +#' assert_no_missing_names(x, "a") +#' try(assert_no_missing_names(x, "bad")) #' #' @noRd -assert_missing_names <- function(data, expected_names) { +assert_no_missing_names <- function(data, expected_names) { if (!rlang::is_named(data)) { cli::cli_abort( message = c(x = "{.arg data} must be named"), @@ -51,7 +51,7 @@ assert_missing_names <- function(data, expected_names) { } -assert_unknown_values <- function(value, data, column) { +assert_no_unknown_values <- function(value, data, column) { if (is.null(value)) { return(invisible(value)) }