Skip to content

Commit

Permalink
fix assert naming
Browse files Browse the repository at this point in the history
  • Loading branch information
cjyetman committed Nov 13, 2024
1 parent 523d74b commit 580256f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion R/plot_sankey.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
2 changes: 1 addition & 1 deletion R/plot_scatter.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
))
Expand Down
8 changes: 4 additions & 4 deletions R/prep_sankey.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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))) {
Expand Down
10 changes: 5 additions & 5 deletions R/prep_scatter.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
}
10 changes: 5 additions & 5 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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"),
Expand Down Expand Up @@ -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))
}
Expand Down

0 comments on commit 580256f

Please sign in to comment.