Skip to content

Commit d4c13df

Browse files
committed
fix: proper rlang imports and types check
1 parent eba2c8f commit d4c13df

6 files changed

Lines changed: 72 additions & 69 deletions

File tree

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@
1818
^codemeta\.json$
1919
^CODE_OF_CONDUCT\.md$
2020
^src/.*\.o$
21+
^dev\.R$

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ Depends: R (>= 4.1.0)
1111
Imports:
1212
Rcpp (>= 1.0.12),
1313
rlang (>= 1.1.0),
14-
yardstick (>= 1.3.1)
14+
yardstick (>= 1.3.1),
15+
cli
1516
LinkingTo: Rcpp
1617
Roxygen: list(markdown = TRUE)
1718
RoxygenNote: 7.3.2

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
useDynLib(tidyhydro, .registration = TRUE)
22
importFrom(Rcpp, evalCpp)
3+
import(rlang)
34
# exportPattern("^[[:alpha:]]+")
45

56
S3method(nse, data.frame)

R/aaa-new.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ new_sym_measure <- function(fn) {
3838
}
3939

4040
#' @include import-standalone-types-check.R
41-
new_measure <- function(fn, direction, class = NULL, call = caller_env()) {
41+
new_measure <- function(fn, class = NULL, call = caller_env()) {
4242
check_function(fn, call = call)
4343

4444
class <- c(class, "measure", "function")

R/import-standalone-obj-type.R

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
#' article, e.g. "an integer vector".
6868
#' @noRd
6969
obj_type_friendly <- function(x, value = TRUE) {
70-
if (rlang::is_missing(x)) {
70+
if (is_missing(x)) {
7171
return("absent")
7272
}
7373

@@ -80,15 +80,15 @@ obj_type_friendly <- function(x, value = TRUE) {
8080
return(sprintf("a <%s> object", type))
8181
}
8282

83-
if (!rlang::is_vector(x)) {
83+
if (!is_vector(x)) {
8484
return(.rlang_as_friendly_type(typeof(x)))
8585
}
8686

8787
n_dim <- length(dim(x))
8888

8989
if (!n_dim) {
90-
if (!rlang::is_list(x) && length(x) == 1) {
91-
if (rlang::is_na(x)) {
90+
if (!is_list(x) && length(x) == 1) {
91+
if (is_na(x)) {
9292
return(switch(
9393
typeof(x),
9494
logical = "`NA`",
@@ -173,8 +173,8 @@ obj_type_friendly <- function(x, value = TRUE) {
173173
}
174174

175175
vec_type_friendly <- function(x, length = FALSE) {
176-
if (!rlang::is_vector(x)) {
177-
rlang::abort("`x` must be a vector.")
176+
if (!is_vector(x)) {
177+
abort("`x` must be a vector.")
178178
}
179179
type <- typeof(x)
180180
n_dim <- length(dim(x))
@@ -260,8 +260,8 @@ vec_type_friendly <- function(x, length = FALSE) {
260260
)
261261
}
262262

263-
.rlang_stop_unexpected_typeof <- function(x, call = rlang::caller_env()) {
264-
rlang::abort(
263+
.rlang_stop_unexpected_typeof <- function(x, call = caller_env()) {
264+
abort(
265265
sprintf("Unexpected type <%s>.", typeof(x)),
266266
call = call
267267
)
@@ -296,7 +296,7 @@ obj_type_oo <- function(x) {
296296
#' character vector of expected types, in which case the error
297297
#' message mentions all of them in an "or" enumeration.
298298
#' @param show_value Passed to `value` argument of `obj_type_friendly()`.
299-
#' @param ... Arguments passed to [rlang::abort()].
299+
#' @param ... Arguments passed to [abort()].
300300
#' @inheritParams args_error_context
301301
#' @noRd
302302
stop_input_type <- function(
@@ -306,11 +306,11 @@ stop_input_type <- function(
306306
allow_na = FALSE,
307307
allow_null = FALSE,
308308
show_value = TRUE,
309-
arg = rlang::caller_arg(x),
310-
call = rlang::caller_env()
309+
arg = caller_arg(x),
310+
call = caller_env()
311311
) {
312312
# From standalone-cli.R
313-
cli <- rlang::env_get_list(
313+
cli <- env_get_list(
314314
nms = c("format_arg", "format_code"),
315315
last = topenv(),
316316
default = function(x) sprintf("`%s`", x),
@@ -339,7 +339,7 @@ stop_input_type <- function(
339339
obj_type_friendly(x, value = show_value)
340340
)
341341

342-
rlang::abort(message, ..., call = call, arg = arg)
342+
abort(message, ..., call = call, arg = arg)
343343
}
344344

345345
oxford_comma <- function(chr, sep = ", ", final = "or") {

R/import-standalone-types-check.R

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ check_bool <- function(
7070
...,
7171
allow_na = FALSE,
7272
allow_null = FALSE,
73-
arg = rlang::caller_arg(x),
74-
call = rlang::caller_env()
73+
arg = caller_arg(x),
74+
call = caller_env()
7575
) {
7676
if (
7777
!missing(x) &&
@@ -102,8 +102,8 @@ check_string <- function(
102102
allow_empty = TRUE,
103103
allow_na = FALSE,
104104
allow_null = FALSE,
105-
arg = rlang::caller_arg(x),
106-
call = rlang::caller_env()
105+
arg = caller_arg(x),
106+
call = caller_env()
107107
) {
108108
if (!missing(x)) {
109109
is_string <- .rlang_check_is_string(
@@ -129,13 +129,13 @@ check_string <- function(
129129
}
130130

131131
.rlang_check_is_string <- function(x, allow_empty, allow_na, allow_null) {
132-
if (rlang::is_string(x)) {
133-
if (allow_empty || !rlang::is_string(x, "")) {
132+
if (is_string(x)) {
133+
if (allow_empty || !is_string(x, "")) {
134134
return(TRUE)
135135
}
136136
}
137137

138-
if (allow_null && rlang::is_null(x)) {
138+
if (allow_null && is_null(x)) {
139139
return(TRUE)
140140
}
141141

@@ -150,8 +150,8 @@ check_name <- function(
150150
x,
151151
...,
152152
allow_null = FALSE,
153-
arg = rlang::caller_arg(x),
154-
call = rlang::caller_env()
153+
arg = caller_arg(x),
154+
call = caller_env()
155155
) {
156156
if (!missing(x)) {
157157
is_string <- .rlang_check_is_string(
@@ -188,8 +188,8 @@ check_number_decimal <- function(
188188
allow_infinite = TRUE,
189189
allow_na = FALSE,
190190
allow_null = FALSE,
191-
arg = rlang::caller_arg(x),
192-
call = rlang::caller_env()
191+
arg = caller_arg(x),
192+
call = caller_env()
193193
) {
194194
if (missing(x)) {
195195
exit_code <- IS_NUMBER_false
@@ -231,8 +231,8 @@ check_number_whole <- function(
231231
allow_infinite = FALSE,
232232
allow_na = FALSE,
233233
allow_null = FALSE,
234-
arg = rlang::caller_arg(x),
235-
call = rlang::caller_env()
234+
arg = caller_arg(x),
235+
call = caller_env()
236236
) {
237237
if (missing(x)) {
238238
exit_code <- IS_NUMBER_false
@@ -295,7 +295,7 @@ check_number_whole <- function(
295295
} else if (x > max) {
296296
what <- sprintf("%s smaller than or equal to %s", what, max)
297297
} else {
298-
rlang::abort("Unexpected state in OOB check", .internal = TRUE)
298+
abort("Unexpected state in OOB check", .internal = TRUE)
299299
}
300300
}
301301

@@ -314,14 +314,14 @@ check_symbol <- function(
314314
x,
315315
...,
316316
allow_null = FALSE,
317-
arg = rlang::caller_arg(x),
318-
call = rlang::caller_env()
317+
arg = caller_arg(x),
318+
call = caller_env()
319319
) {
320320
if (!missing(x)) {
321-
if (rlang::is_symbol(x)) {
321+
if (is_symbol(x)) {
322322
return(invisible(NULL))
323323
}
324-
if (allow_null && rlang::is_null(x)) {
324+
if (allow_null && is_null(x)) {
325325
return(invisible(NULL))
326326
}
327327
}
@@ -341,14 +341,14 @@ check_arg <- function(
341341
x,
342342
...,
343343
allow_null = FALSE,
344-
arg = rlang::caller_arg(x),
345-
call = rlang::caller_env()
344+
arg = caller_arg(x),
345+
call = caller_env()
346346
) {
347347
if (!missing(x)) {
348-
if (rlang::is_symbol(x)) {
348+
if (is_symbol(x)) {
349349
return(invisible(NULL))
350350
}
351-
if (allow_null && rlang::is_null(x)) {
351+
if (allow_null && is_null(x)) {
352352
return(invisible(NULL))
353353
}
354354
}
@@ -368,14 +368,14 @@ check_call <- function(
368368
x,
369369
...,
370370
allow_null = FALSE,
371-
arg = rlang::caller_arg(x),
372-
call = rlang::caller_env()
371+
arg = caller_arg(x),
372+
call = caller_env()
373373
) {
374374
if (!missing(x)) {
375-
if (rlang::is_call(x)) {
375+
if (is_call(x)) {
376376
return(invisible(NULL))
377377
}
378-
if (allow_null && rlang::is_null(x)) {
378+
if (allow_null && is_null(x)) {
379379
return(invisible(NULL))
380380
}
381381
}
@@ -395,14 +395,14 @@ check_environment <- function(
395395
x,
396396
...,
397397
allow_null = FALSE,
398-
arg = rlang::caller_arg(x),
399-
call = rlang::caller_env()
398+
arg = caller_arg(x),
399+
call = caller_env()
400400
) {
401401
if (!missing(x)) {
402-
if (rlang::is_environment(x)) {
402+
if (is_environment(x)) {
403403
return(invisible(NULL))
404404
}
405-
if (allow_null && rlang::is_null(x)) {
405+
if (allow_null && is_null(x)) {
406406
return(invisible(NULL))
407407
}
408408
}
@@ -422,14 +422,14 @@ check_function <- function(
422422
x,
423423
...,
424424
allow_null = FALSE,
425-
arg = rlang::caller_arg(x),
426-
call = rlang::caller_env()
425+
arg = caller_arg(x),
426+
call = caller_env()
427427
) {
428428
if (!missing(x)) {
429-
if (rlang::is_function(x)) {
429+
if (is_function(x)) {
430430
return(invisible(NULL))
431431
}
432-
if (allow_null && rlang::is_null(x)) {
432+
if (allow_null && is_null(x)) {
433433
return(invisible(NULL))
434434
}
435435
}
@@ -449,14 +449,14 @@ check_closure <- function(
449449
x,
450450
...,
451451
allow_null = FALSE,
452-
arg = rlang::caller_arg(x),
453-
call = rlang::caller_env()
452+
arg = caller_arg(x),
453+
call = caller_env()
454454
) {
455455
if (!missing(x)) {
456-
if (rlang::is_closure(x)) {
456+
if (is_closure(x)) {
457457
return(invisible(NULL))
458458
}
459-
if (allow_null && rlang::is_null(x)) {
459+
if (allow_null && is_null(x)) {
460460
return(invisible(NULL))
461461
}
462462
}
@@ -476,14 +476,14 @@ check_formula <- function(
476476
x,
477477
...,
478478
allow_null = FALSE,
479-
arg = rlang::caller_arg(x),
480-
call = rlang::caller_env()
479+
arg = caller_arg(x),
480+
call = caller_env()
481481
) {
482482
if (!missing(x)) {
483-
if (rlang::is_formula(x)) {
483+
if (is_formula(x)) {
484484
return(invisible(NULL))
485485
}
486-
if (allow_null && rlang::is_null(x)) {
486+
if (allow_null && is_null(x)) {
487487
return(invisible(NULL))
488488
}
489489
}
@@ -509,13 +509,13 @@ check_character <- function(
509509
...,
510510
allow_na = TRUE,
511511
allow_null = FALSE,
512-
arg = rlang::caller_arg(x),
513-
call = rlang::caller_env()
512+
arg = caller_arg(x),
513+
call = caller_env()
514514
) {
515515
if (!missing(x)) {
516-
if (rlang::is_character(x)) {
516+
if (is_character(x)) {
517517
if (!allow_na && any(is.na(x))) {
518-
rlang::abort(
518+
abort(
519519
sprintf("`%s` can't contain NA values.", arg),
520520
arg = arg,
521521
call = call
@@ -525,7 +525,7 @@ check_character <- function(
525525
return(invisible(NULL))
526526
}
527527

528-
if (allow_null && rlang::is_null(x)) {
528+
if (allow_null && is_null(x)) {
529529
return(invisible(NULL))
530530
}
531531
}
@@ -544,14 +544,14 @@ check_logical <- function(
544544
x,
545545
...,
546546
allow_null = FALSE,
547-
arg = rlang::caller_arg(x),
548-
call = rlang::caller_env()
547+
arg = caller_arg(x),
548+
call = caller_env()
549549
) {
550550
if (!missing(x)) {
551-
if (rlang::is_logical(x)) {
551+
if (is_logical(x)) {
552552
return(invisible(NULL))
553553
}
554-
if (allow_null && rlang::is_null(x)) {
554+
if (allow_null && is_null(x)) {
555555
return(invisible(NULL))
556556
}
557557
}
@@ -571,14 +571,14 @@ check_data_frame <- function(
571571
x,
572572
...,
573573
allow_null = FALSE,
574-
arg = rlang::caller_arg(x),
575-
call = rlang::caller_env()
574+
arg = caller_arg(x),
575+
call = caller_env()
576576
) {
577577
if (!missing(x)) {
578578
if (is.data.frame(x)) {
579579
return(invisible(NULL))
580580
}
581-
if (allow_null && rlang::is_null(x)) {
581+
if (allow_null && is_null(x)) {
582582
return(invisible(NULL))
583583
}
584584
}

0 commit comments

Comments
 (0)