Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
40 changes: 16 additions & 24 deletions R/helpers.R
Original file line number Diff line number Diff line change
@@ -1,39 +1,23 @@
#' Generator function so that the functions can be generated programmatically.
#' @noRd
.check_pick_generator <- function(attr_name) {
rlang::new_function(
rlang::pairlist2(x = ),
substitute(
{
checkmate::assert_class(x, classes = c("pick"))
checkmate::assert_flag(attr(x, attr_name, exact = TRUE))
isTRUE(attr(x, attr_name, exact = TRUE))
},
env = list(attr_name = attr_name)
),
env = parent.frame()
)
}

#' Helper functions for pick
#' Helper functions to check pick attributes
#' @description
#' Helper functions for pick objects generated from
#' [datasets()], [variables()] or [values()]:
#' @name helper_functions_pick
#' @param x (`datasets`, `variables` or `values`) pick to check.
#' @return `TRUE` if the pick has the attribute set to `TRUE`,
#' `FALSE` otherwise.


#' @rdname helper_functions_pick
#' @description
#' - `is_pick_multiple()` checks if a pick has the `multiple` attribute set to `TRUE`.
#' @examples
#' p <- picks(datasets("iris"), variables(), values())
#'
#' is_pick_multiple(p$variables)
#' @export
is_pick_multiple <- .check_pick_generator("multiple")
is_pick_multiple <- function(x) {
checkmate::assert_class(x, classes = c("pick"))
checkmate::assert_flag(attr(x, "multiple", exact = TRUE))
isTRUE(attr(x, "multiple", exact = TRUE))
}

#' @rdname helper_functions_pick
#' @description
Expand All @@ -42,7 +26,11 @@ is_pick_multiple <- .check_pick_generator("multiple")
#'
#' is_pick_fixed(p$variables)
#' @export
is_pick_fixed <- .check_pick_generator("fixed")
is_pick_fixed <- function(x) {
checkmate::assert_class(x, classes = c("pick"))
checkmate::assert_flag(attr(x, "fixed", exact = TRUE))
isTRUE(attr(x, "fixed", exact = TRUE))
}

#' @rdname helper_functions_pick
#' @description
Expand All @@ -51,4 +39,8 @@ is_pick_fixed <- .check_pick_generator("fixed")
#'
#' is_pick_ordered(p$variables)
#' @export
is_pick_ordered <- .check_pick_generator("ordered")
is_pick_ordered <- function(x) {
checkmate::assert_class(x, classes = c("pick"))
checkmate::assert_flag(attr(x, "ordered", exact = TRUE))
isTRUE(attr(x, "ordered", exact = TRUE))
}
2 changes: 1 addition & 1 deletion man/helper_functions_pick.Rd

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

Loading