Skip to content

Commit 7cb17b4

Browse files
committed
ggalign_attr gains a new argument "check"
1 parent 019c107 commit 7cb17b4

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Diff for: R/layout-.R

+7-2
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,20 @@ ggalign_stat.AlignGg <- ggalign_stat.default
188188
#' @param field A string specifying the particular data to retrieve from the
189189
#' attached attribute. If `NULL`, the entire attached attribute list will be
190190
#' returned.
191-
#'
191+
#' @param check A boolean indicating whether to check if the `field` exists. If
192+
#' `TRUE`, an error will be raised if the specified `field` does not exist.
192193
#' @return The specified data from the attached attribute or `NULL` if it is
193194
#' unavailable.
194195
#'
195196
#' @export
196-
ggalign_attr <- function(x, field = NULL) {
197+
ggalign_attr <- function(x, field = NULL, check = TRUE) {
198+
assert_string(field, allow_null = TRUE)
197199
if (is.null(x <- ggalign_attr_get(x)) || is.null(field)) {
198200
return(x)
199201
}
202+
if (isTRUE(check) && !rlang::has_name(x, field)) {
203+
cli_abort("Cannot find {field} in {.arg x}")
204+
}
200205
.subset2(x, field)
201206
}
202207

Diff for: man/ggalign_attr.Rd

+4-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)