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
60 changes: 60 additions & 0 deletions R/specify_chr.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#' Create a specified character stabilizer function
#'
#' `specify_chr()` creates a function that will call [stabilize_chr()] with the
#' provided arguments. `specify_chr_scalar()` creates a function that will call
#' [stabilize_chr_scalar()] with the provided arguments. `specify_character()`
#' is a synonym of `specify_chr()`, and `specify_character_scalar()` is a
#' synonym of `specify_chr_scalar()`.
#'
#' @inheritParams .shared-params
#' @returns A function of class `"stbl_specified_fn"` that calls
#' [stabilize_chr()] or [stabilize_chr_scalar()] with the provided arguments.
#' The generated function will also accept `...` for additional arguments to
#' pass to [stabilize_chr()] or [stabilize_chr_scalar()]. You can copy/paste
#' the body of the resulting function if you want to provide additional
#' context or functionality.
#' @family character functions
#' @family specification functions
#' @export
#'
#' @examples
#' stabilize_email <- specify_chr(regex = "^[^@]+@[^@]+\\.[^@]+$")
#' stabilize_email("stbl@example.com")
#' try(stabilize_email("not-an-email-address"))
specify_chr <- function(
allow_null = TRUE,
allow_na = TRUE,
min_size = NULL,
max_size = NULL,
unique = FALSE,
min_characters = NULL,
max_characters = NULL,
regex = NULL,
allowed_values = NULL
) {
factory_args <- .capture_factory_args()
.specify_cls("chr", factory_args)
}

#' @export
#' @rdname specify_chr
specify_chr_scalar <- function(
allow_null = FALSE,
allow_zero_length = FALSE,
allow_na = TRUE,
min_characters = NULL,
max_characters = NULL,
regex = NULL,
allowed_values = NULL
) {
factory_args <- .capture_factory_args()
.specify_cls("chr", factory_args, scalar = TRUE)
}

#' @export
#' @rdname specify_chr
specify_character <- specify_chr

#' @export
#' @rdname specify_chr
specify_character_scalar <- specify_chr_scalar
Loading
Loading