Skip to content

Commit ea8d1fd

Browse files
committed
Add structure and choice assertions
1 parent 4e24437 commit ea8d1fd

File tree

5 files changed

+71
-3
lines changed

5 files changed

+71
-3
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: zmisc
33
Title: Vector Look-Ups and Safer Sampling
4-
Version: 0.2.3.9005
4+
Version: 0.2.3.9006
55
Author: Magnus Thor Torfason
66
Maintainer: Magnus Thor Torfason <[email protected]>
77
Description: A collection of utility functions that facilitate looking up

NAMESPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ S3method(notate,haven_labelled)
77
S3method(notate,ordered)
88
export("ll_val_labels<-")
99
export("ll_var_label<-")
10+
export(assert_atomic)
1011
export(assert_character)
12+
export(assert_choice)
13+
export(assert_class)
1114
export(assert_complex)
1215
export(assert_count)
1316
export(assert_data_frame)
@@ -29,6 +32,7 @@ export(assert_naturalish)
2932
export(assert_number)
3033
export(assert_numeric)
3134
export(assert_raw)
35+
export(assert_scalar)
3236
export(assert_string)
3337
export(assert_tibble)
3438
export(ddply_helper)

R/assertions.R

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,23 @@ assert_date <- function(x, ...) {
299299
invisible(x)
300300
}
301301

302+
# --- Type, class, and structure assertions ----
302303

303-
#### Lists and tibbles
304+
#' @rdname checkmate_rlang
305+
#' @export
306+
assert_scalar <- function(x, ...) {
307+
if (!isTRUE(check_scalar(x, ...)))
308+
rlang::abort(check_scalar(x, ...))
309+
invisible(x)
310+
}
304311

312+
#' @rdname checkmate_rlang
313+
#' @export
314+
assert_atomic <- function(x, ...) {
315+
if (!isTRUE(check_atomic(x, ...)))
316+
rlang::abort(check_atomic(x, ...))
317+
invisible(x)
318+
}
305319

306320
#' @rdname checkmate_rlang
307321
#' @export
@@ -311,6 +325,26 @@ assert_list <- function(x, ...) {
311325
invisible(x)
312326
}
313327

328+
#' @rdname checkmate_rlang
329+
#' @export
330+
assert_list <- function(x, ...) {
331+
if (!isTRUE(check_list(x, ...)))
332+
rlang::abort(check_list(x, ...))
333+
invisible(x)
334+
}
335+
336+
337+
#' @rdname checkmate_rlang
338+
#' @export
339+
assert_class <- function(x, ...) {
340+
if (!isTRUE(check_class(x, ...)))
341+
rlang::abort(check_class(x, ...))
342+
invisible(x)
343+
}
344+
345+
346+
# --- Tibble and data.frame assertions ----
347+
314348
#' @rdname checkmate_rlang
315349
#' @export
316350
assert_data_frame <- function(x, ...) {
@@ -334,3 +368,16 @@ assert_tibble <- function(x, ...) {
334368
rlang::abort(check_tibble(x, ...))
335369
invisible(x)
336370
}
371+
372+
373+
# --- Set and value assertions ----
374+
375+
376+
#' @rdname checkmate_rlang
377+
#' @export
378+
assert_choice <- function(x, choices, ...) {
379+
if (!isTRUE(check_choice(x, choices, ...)))
380+
rlang::abort(check_choice(x, choices, ...))
381+
invisible(x)
382+
}
383+

man/checkmate_rlang.Rd

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-zzz_spelling.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11

22
test_that("There are no spelling errors", {
3-
extract2 <- .Primitive("[[")
3+
skip_on_cran()
44
if (!file.exists(here::here("DESCRIPTION")))
55
skip("Skipping, this only runs through testthat tests.")
6+
7+
# The actual test if we are not skipping it
8+
extract2 <- .Primitive("[[")
69
spelling::spell_check_package(here::here()) |>
710
extract2("word") |>
811
expect_equal(character())

0 commit comments

Comments
 (0)