Skip to content

Deprecate val_class_or_null() and val_class_and_single() #1161

@hfrick

Description

@hfrick

Summary

val_class_or_null() and val_class_and_single() are exported but marked with TODO comments indicating they should be removed once finetune is updated. Each has a corresponding unexported helper (check_class_or_null(), check_class_and_single()).

Locations

val_class_or_null() and check_class_or_null():

tune/R/checks.R

Lines 563 to 585 in 3544816

check_class_or_null <- function(x, cls = "numeric") {
inherits(x, cls) | is.null(x)
}
#' @export
#' @keywords internal
#' @rdname empty_ellipses
#' @param cls A character vector of possible classes
#' @param where A character string for the calling function.
val_class_or_null <- function(x, cls = "numeric", where = NULL) {
cl <- match.call()
fine <- check_class_or_null(x, cls)
cls <- paste(cls, collapse = " or ")
if (!fine) {
msg <- glue::glue("Argument '{deparse(cl$x)}' should be a {cls} or NULL")
if (!is.null(where)) {
msg <- glue::glue(msg, " in `{where}`")
}
rlang::abort(msg)
}
invisible(NULL)
}
# TODO remove this once finetune is updated

val_class_and_single() and check_class_and_single():

tune/R/checks.R

Lines 587 to 609 in 3544816

check_class_and_single <- function(x, cls = "numeric") {
isTRUE(inherits(x, cls) & length(x) == 1)
}
#' @export
#' @keywords internal
#' @rdname empty_ellipses
val_class_and_single <- function(x, cls = "numeric", where = NULL) {
cl <- match.call()
fine <- check_class_and_single(x, cls)
cls <- paste(cls, collapse = " or ")
if (!fine) {
msg <- glue::glue(
"Argument '{deparse(cl$x)}' should be a single {cls} value"
)
if (!is.null(where)) {
msg <- glue::glue(msg, " in `{where}`")
}
rlang::abort(msg)
}
invisible(NULL)
}
# TODO remove this once finetune is updated

Current status

Both val_class_* functions are exported for finetune's benefit. The TODO comments on lines 585 and 609 say:

# TODO remove this once finetune is updated

Neither function is called within tune itself (R/, tests/, or inst/).

Suggested fix

Check whether finetune still uses these functions. If so, open an issue on finetune. Deprecate all four functions (val_class_or_null(), check_class_or_null(), val_class_and_single(), check_class_and_single()) and remove their export/documentation entries.

Metadata

Metadata

Assignees

No one assigned

    Labels

    upkeepmaintenance, infrastructure, and similar

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions