Skip to content

Commit

Permalink
simplify file structure
Browse files Browse the repository at this point in the history
renames files that define an `adjust_*()` function and associated method as `adjust_function_name.R`. helps to differentiate this relatively homogenous file type from other kinds of source files.
  • Loading branch information
simonpcouch committed Apr 22, 2024
1 parent b92edb0 commit 809da4a
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 42 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion R/container.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ new_container <- function(mode, type, operations, columns, ptype, call) {
}

# validate operation order and check duplicates
validate_oper_order(operations, mode, call)
validate_order(operations, mode, call)

# check columns
res <- list(
Expand Down
29 changes: 0 additions & 29 deletions R/operation.R

This file was deleted.

30 changes: 30 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,33 @@ no_param <-
component = character(0),
component_id = character(0)
)

# These values are used to specify "what will we need for the adjustment?" and
# "what will we change?". For the outputs, we cannot change the probabilities
# without changing the classes. This is important because we are going to have
# to define constrains on the order of adjustments.

input_vals <- c("numeric", "probability", "class", "everything")
output_vals <- c("numeric", "probability_class", "class", "everything")

new_operation <- function(cls, inputs, outputs, arguments, results = list(trained = FALSE), ...) {
inputs <- arg_match0(inputs, input_vals)
outputs <- arg_match0(outputs, output_vals)

if (!any(names(results) == "trained")) {
cli_abort("The {.arg results} slot requires a logical variable called \\
{.val trained}")
} else {
check_logical(results$trained)
}

res <-
list(
inputs = inputs,
outputs = outputs,
arguments = arguments,
results = results
)
class(res) <- c(cls, "operation")
res
}
12 changes: 6 additions & 6 deletions R/validation-rules.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
validate_oper_order <- function(ops, mode, call) {
oper_data <-
validate_order <- function(ops, mode, call) {
orderings <-
tibble::new_tibble(list(
name = purrr::map_chr(ops, ~ class(.x)[1]),
input = purrr::map_chr(ops, ~ .x$inputs),
Expand All @@ -10,16 +10,16 @@ validate_oper_order <- function(ops, mode, call) {
))

if (length(ops) < 2) {
return(invisible(oper_data))
return(invisible(orderings))
}

if (mode == "classification") {
check_classification_order(oper_data, call)
check_classification_order(orderings, call)
} else {
check_regression_order(oper_data, call)
check_regression_order(orderings, call)
}

invisible(oper_data)
invisible(orderings)
}

check_classification_order <- function(x, call) {
Expand Down
2 changes: 1 addition & 1 deletion man/adjust_equivocal_zone.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/adjust_numeric_calibration.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/adjust_numeric_range.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/adjust_predictions_custom.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/adjust_probability_calibration.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/adjust_probability_threshold.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 809da4a

Please sign in to comment.