25
25
validate_version_bound <- function (version_bound , x , na_ok = FALSE ,
26
26
version_bound_arg = rlang :: caller_arg(version_bound ),
27
27
x_arg = rlang :: caller_arg(version_bound )) {
28
-
29
- if (na_ok && is.na(version_bound )) return (invisible (NULL ))
30
- checkmate :: assert_set_equal(class(version_bound ), class(x [[" version" ]]), .var.name = version_bound_arg )
31
- checkmate :: assert_set_equal(typeof(version_bound ), typeof(x [[" version" ]]), .var.name = version_bound_arg )
28
+ if (is.null(version_bound )) {
29
+ cli_abort(
30
+ " {version_bound_arg} cannot be NULL"
31
+ )
32
+ }
33
+ if (na_ok && is.na(version_bound )) {
34
+ return (invisible (NULL ))
35
+ }
36
+ if (! test_set_equal(class(version_bound ), class(x [[" version" ]]))) {
37
+ cli_abort(
38
+ " {version_bound_arg} must have the same classes as x$version,
39
+ which is {class(x$version)}" ,
40
+ )
41
+ }
42
+ if (! test_set_equal(typeof(version_bound ), typeof(x [[" version" ]]))) {
43
+ cli_abort(
44
+ " {version_bound_arg} must have the same types as x$version,
45
+ which is {typeof(x$version)}" ,
46
+ )
47
+ }
32
48
33
49
return (invisible (NULL ))
34
50
}
@@ -251,26 +267,15 @@ epi_archive <-
251
267
initialize = function (x , geo_type , time_type , other_keys ,
252
268
additional_metadata , compactify ,
253
269
clobberable_versions_start , versions_end ) {
254
- # Check that we have a data frame
255
- if (! is.data.frame(x )) {
256
- cli_abort(" `x` must be a data frame." )
257
- }
258
-
259
- # Check that we have geo_value, time_value, version columns
260
- if (! (" geo_value" %in% names(x ))) {
261
- cli_abort(" `x` must contain a `geo_value` column." )
262
- }
263
- if (! (" time_value" %in% names(x ))) {
264
- cli_abort(" `x` must contain a `time_value` column." )
265
- }
266
- if (! (" version" %in% names(x ))) {
267
- cli_abort(" `x` must contain a `version` column." )
268
- }
269
- if (anyNA(x $ version )) {
270
- cli_abort(" `x$version` must not contain `NA`s" ,
271
- class = " epiprocess__version_values_must_not_be_na"
270
+ assert_data_frame(x )
271
+ if (! test_subset(c(" geo_value" , " time_value" , " version" ), names(x ))) {
272
+ cli_abort(
273
+ " Columns `geo_value`, `time_value`, and `version` must be present in `x`."
272
274
)
273
275
}
276
+ if (anyMissing(x $ version )) {
277
+ cli_abort(" Column `version` must not contain missing values." )
278
+ }
274
279
275
280
# If geo type is missing, then try to guess it
276
281
if (missing(geo_type )) {
@@ -285,7 +290,7 @@ epi_archive <-
285
290
# Finish off with small checks on keys variables and metadata
286
291
if (missing(other_keys )) other_keys <- NULL
287
292
if (missing(additional_metadata )) additional_metadata <- list ()
288
- if (! all (other_keys %in% names(x ))) {
293
+ if (! test_subset (other_keys , names(x ))) {
289
294
cli_abort(" `other_keys` must be contained in the column names of `x`." )
290
295
}
291
296
if (any(c(" geo_value" , " time_value" , " version" ) %in% other_keys )) {
@@ -298,10 +303,8 @@ epi_archive <-
298
303
# Conduct checks and apply defaults for `compactify`
299
304
if (missing(compactify )) {
300
305
compactify <- NULL
301
- } else if (! rlang :: is_bool(compactify ) &&
302
- ! rlang :: is_null(compactify )) {
303
- cli_abort(" compactify must be boolean or null." )
304
306
}
307
+ assert_logical(compactify , len = 1 , null.ok = TRUE )
305
308
306
309
# Apply defaults and conduct checks for
307
310
# `clobberable_versions_start`, `versions_end`:
@@ -384,7 +387,7 @@ epi_archive <-
384
387
elim <- tibble :: tibble()
385
388
}
386
389
387
- # cli_warns about redundant rows
390
+ # Warns about redundant rows
388
391
if (is.null(compactify ) && nrow(elim ) > 0 ) {
389
392
warning_intro <- cli :: format_inline(
390
393
" Found rows that appear redundant based on
@@ -436,7 +439,7 @@ epi_archive <-
436
439
)
437
440
)
438
441
439
- return (invisible (self $ DT %> % print ))
442
+ return (invisible (self $ DT %> % print() ))
440
443
},
441
444
# ####
442
445
# ' @description Generates a snapshot in `epi_df` format as of a given version.
@@ -467,22 +470,21 @@ epi_archive <-
467
470
if (length(other_keys ) == 0 ) other_keys <- NULL
468
471
469
472
# Check a few things on max_version
470
- if (! identical(class(max_version ), class(self $ DT $ version )) ||
471
- ! identical(typeof(max_version ), typeof(self $ DT $ version ))) {
472
- cli_abort(" `max_version` and `DT$version` must have same `class` and `typeof`." )
473
- }
474
- if (length(max_version ) != 1 ) {
475
- cli_abort(" `max_version` cannot be a vector." )
473
+ if (! test_set_equal(class(max_version ), class(self $ DT $ version ))) {
474
+ cli_abort(
475
+ " `max_version` must have the same classes as `self$DT$version`."
476
+ )
476
477
}
477
- if (is.na(max_version )) {
478
- cli_abort(" `max_version` must not be NA." )
478
+ if (! test_set_equal(typeof(max_version ), typeof(self $ DT $ version ))) {
479
+ cli_abort(
480
+ " `max_version` must have the same types as `self$DT$version`."
481
+ )
479
482
}
483
+ assert_scalar(max_version , na.ok = FALSE )
480
484
if (max_version > self $ versions_end ) {
481
485
cli_abort(" `max_version` must be at most `self$versions_end`." )
482
486
}
483
- if (! rlang :: is_bool(all_versions )) {
484
- cli_abort(" `all_versions` must be TRUE or FALSE." )
485
- }
487
+ assert_logical(all_versions , len = 1 )
486
488
if (! is.na(self $ clobberable_versions_start ) && max_version > = self $ clobberable_versions_start ) {
487
489
cli_warn(
488
490
' Getting data as of some recent version which could still be
@@ -599,16 +601,13 @@ epi_archive <-
599
601
# ' @param x as in [`epix_truncate_versions_after`]
600
602
# ' @param max_version as in [`epix_truncate_versions_after`]
601
603
truncate_versions_after = function (max_version ) {
602
- if (length(max_version ) != 1 ) {
603
- cli_abort(" `max_version` cannot be a vector." )
604
- }
605
- if (is.na(max_version )) {
606
- cli_abort(" `max_version` must not be NA." )
604
+ if (! test_set_equal(class(max_version ), class(self $ DT $ version ))) {
605
+ cli_abort(" `max_version` must have the same classes as `self$DT$version`." )
607
606
}
608
- if (! identical(class(max_version ), class(self $ DT $ version )) ||
609
- ! identical(typeof(max_version ), typeof(self $ DT $ version ))) {
610
- cli_abort(" `max_version` and `DT$version` must have same `class` and `typeof`." )
607
+ if (! test_set_equal(typeof(max_version ), typeof(self $ DT $ version ))) {
608
+ cli_abort(" `max_version` must have the same types as `self$DT$version`." )
611
609
}
610
+ assert_scalar(max_version , na.ok = FALSE )
612
611
if (max_version > self $ versions_end ) {
613
612
cli_abort(" `max_version` must be at most `self$versions_end`." )
614
613
}
0 commit comments