-
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.
* Implement to_lgl(). * Check internal function args. * Redocument.
- Loading branch information
1 parent
3722dca
commit 450185d
Showing
20 changed files
with
497 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.is_allowed_null <- function(x, | ||
allow_null = TRUE, | ||
call = rlang::caller_env()) { | ||
allow_null <- to_lgl( | ||
allow_null, | ||
allow_null = FALSE, | ||
call = call | ||
) | ||
|
||
return(is.null(x) && allow_null) | ||
} |
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,82 @@ | ||
#' Coerce an argument to logical | ||
#' | ||
#' If a value can be coerced to a logical without losing information, do so | ||
#' silently. Otherwise throw an informative error. | ||
#' | ||
#' @inheritParams .coerce-params | ||
#' | ||
#' @return A logical vector equivalent to `x`. | ||
#' @export | ||
#' | ||
#' @examples | ||
#' to_lgl(TRUE) | ||
#' to_lgl("TRUE") | ||
#' to_lgl(1:10) | ||
#' to_lgl(NULL) | ||
#' try(to_lgl(NULL, allow_null = FALSE)) | ||
#' try(to_lgl(letters)) | ||
#' try(to_lgl(list(TRUE))) | ||
to_lgl <- function(x, | ||
allow_null = TRUE, | ||
x_arg = rlang::caller_arg(x), | ||
call = rlang::caller_env(), | ||
x_class = object_type(x)) { | ||
UseMethod("to_lgl") | ||
} | ||
|
||
#' @export | ||
to_lgl.logical <- function(x, ...) { | ||
return(x) | ||
} | ||
|
||
#' @export | ||
to_lgl.NULL <- function(x, | ||
..., | ||
allow_null = TRUE, | ||
x_arg = rlang::caller_arg(x), | ||
call = rlang::caller_env()) { | ||
to_null(x, allow_null = allow_null, x_arg = x_arg, call = call) | ||
} | ||
|
||
#' @export | ||
to_lgl.integer <- function(x, | ||
..., | ||
x_arg = rlang::caller_arg(x), | ||
call = rlang::caller_env()) { | ||
return(as.logical(x)) | ||
} | ||
|
||
#' @export | ||
to_lgl.double <- function(x, | ||
..., | ||
x_arg = rlang::caller_arg(x), | ||
call = rlang::caller_env()) { | ||
return(as.logical(x)) | ||
} | ||
|
||
#' @export | ||
to_lgl.character <- function(x, | ||
..., | ||
x_arg = rlang::caller_arg(x), | ||
call = rlang::caller_env(), | ||
x_class = object_type(x)) { | ||
cast <- as.logical(toupper(x)) | ||
failures <- xor(is.na(x), is.na(cast)) | ||
|
||
if (any(failures)) { | ||
.stop_incompatible( | ||
x_class, logical(), failures, | ||
due_to = "incompatible values", x_arg, call | ||
) | ||
} | ||
|
||
return(cast) | ||
} | ||
|
||
to_lgl.default <- function(x, | ||
..., | ||
x_arg = rlang::caller_arg(x), | ||
call = rlang::caller_env(), | ||
x_class = object_type(x)) { | ||
.stop_cant_coerce(from_class = x_class, to_class = "logical", call = call) | ||
} |
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,10 @@ | ||
to_null <- function(x, | ||
allow_null = TRUE, | ||
x_arg = rlang::caller_arg(x), | ||
call = rlang::caller_env()) { | ||
allow_null <- to_lgl(allow_null, allow_null = FALSE, call = call) | ||
if (allow_null) { | ||
return(NULL) | ||
} | ||
.stop_null(x_arg, call) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.