-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #28. Also switched to to_lgl_scalar() wherever possible internally, and abstracted the stabilize_cls functions.
- Loading branch information
1 parent
485954e
commit cd7bd08
Showing
23 changed files
with
486 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#' Ensure a logical argument meets expectations | ||
#' | ||
#' Check a logical argument to ensure that it meets expectations, coercing it | ||
#' to logical where possible. If the argument does not meet the requirements, | ||
#' the user will receive an informative error message. Note that [to_lgl()] is a | ||
#' faster version of this function with fewer options. | ||
#' | ||
#' @inheritParams .coerce-params | ||
#' @inheritParams to_lgl | ||
#' | ||
#' @return The argument as a logical vector. | ||
#' @export | ||
#' | ||
#' @examples | ||
#' stabilize_lgl(c(TRUE, FALSE, TRUE)) | ||
#' stabilize_lgl("true") | ||
#' stabilize_lgl(NULL) | ||
#' try(stabilize_lgl(NULL, allow_null = FALSE)) | ||
#' try(stabilize_lgl(c(TRUE, NA), allow_na = FALSE)) | ||
#' try(stabilize_lgl(letters)) | ||
#' try(stabilize_lgl(c(TRUE, FALSE, TRUE), min_size = 5)) | ||
#' try(stabilize_lgl(c(TRUE, FALSE, TRUE), max_size = 2)) | ||
stabilize_lgl <- function(x, | ||
..., | ||
allow_null = TRUE, | ||
allow_na = TRUE, | ||
min_size = NULL, | ||
max_size = NULL, | ||
x_arg = rlang::caller_arg(x), | ||
call = rlang::caller_env(), | ||
x_class = object_type(x)) { | ||
.stabilize_cls( | ||
x, | ||
to_cls_fn = to_lgl, | ||
allow_null = allow_null, | ||
allow_na = allow_na, | ||
min_size = min_size, | ||
max_size = max_size, | ||
x_arg = x_arg, | ||
call = call, | ||
x_class = x_class, | ||
... | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#' Ensure a logical argument meets expectations and is length-1 | ||
#' | ||
#' This function is equivalent to [stabilize_lgl()], but it is optimized to | ||
#' check for length-1 logical vectors. | ||
#' | ||
#' @inheritParams stabilize_lgl | ||
#' | ||
#' @return `x`, unless one of the checks fails. | ||
#' @export | ||
#' | ||
#' @examples | ||
#' stabilize_lgl_scalar(TRUE) | ||
#' stabilize_lgl_scalar("TRUE") | ||
#' try(stabilize_lgl_scalar(c(TRUE, FALSE, TRUE))) | ||
#' stabilize_lgl_scalar(NULL) | ||
#' try(stabilize_lgl_scalar(NULL, allow_null = FALSE)) | ||
stabilize_lgl_scalar <- function(x, | ||
..., | ||
allow_null = TRUE, | ||
allow_na = TRUE, | ||
x_arg = rlang::caller_arg(x), | ||
call = rlang::caller_env(), | ||
x_class = object_type(x)) { | ||
.stabilize_cls_scalar( | ||
x, | ||
to_cls_fn = to_lgl, | ||
allow_null = allow_null, | ||
allow_na = allow_na, | ||
x_arg = x_arg, | ||
call = call, | ||
x_class = x_class, | ||
... | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.