Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional check functions #86

Merged
merged 11 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export(schedule_decay_time)
export(schedule_step)
export(set_learn_rate)
export(tunable)
import(rlang)
import(torch)
importFrom(dplyr,"%>%")
importFrom(generics,tunable)
Expand Down
1 change: 1 addition & 0 deletions R/aaa.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#' @import torch
#' @import rlang
#' @importFrom stats complete.cases model.matrix terms
#' @importFrom utils globalVariables
#'
Expand Down
40 changes: 40 additions & 0 deletions R/checks.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,43 @@
# Additional type checkers designed for testing argument values.

check_single_logical <- function(x, call = rlang::caller_env()) {
topepo marked this conversation as resolved.
Show resolved Hide resolved
topepo marked this conversation as resolved.
Show resolved Hide resolved
cl <- match.call()
arg_nm <- as.character(cl$x)
msg <- "{.arg {arg_nm}} should be a single logical value, not {brulee:::obj_type_friendly(x)}."
if (!is.logical(x)) {
cli::cli_abort(msg, call = call)
}
if (length(x) > 1 || any(is.na(x))) {
cli::cli_abort(msg, call = call)
}
invisible(x)
}

check_number_whole_vec <- function(x, call = rlang::caller_env(), ...) {
cl <- match.call()
arg <- as.character(cl$x)
topepo marked this conversation as resolved.
Show resolved Hide resolved
topepo marked this conversation as resolved.
Show resolved Hide resolved

for (i in x) {
topepo marked this conversation as resolved.
Show resolved Hide resolved
rlang:::check_number_whole(i, arg = arg, call = call, ...)
}
x <- as.integer(x)
topepo marked this conversation as resolved.
Show resolved Hide resolved
invisible(x)
}

check_number_decimal_vec <- function(x, call = rlang::caller_env(), ...) {
topepo marked this conversation as resolved.
Show resolved Hide resolved
cl <- match.call()
arg <- as.character(cl$x)
topepo marked this conversation as resolved.
Show resolved Hide resolved

for (i in x) {
rlang:::check_number_decimal(i, arg = arg, call = call, ...)
}
invisible(x)
}

# ------------------------------------------------------------------------------
# soon to be replaced checkers


check_missing_data <- function(x, y, fn = "some function", verbose = FALSE) {
compl_data <- complete.cases(x, y)
if (any(!compl_data)) {
Expand Down
Loading
Loading