Skip to content

Commit

Permalink
Use rlang::check_exclusive() (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley authored Sep 12, 2024
1 parent 9061761 commit f1b5d50
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Depends:
R (>= 4.0)
Imports:
htmlwidgets (>= 0.3.2),
rlang (>= 0.4.9),
rlang (>= 1.1.0),
vctrs
Suggests:
htmltools,
Expand Down
8 changes: 2 additions & 6 deletions R/profvis.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,11 @@ profvis <- function(expr = NULL,
torture = 0,
simplify = TRUE,
rerun = FALSE) {
check_exclusive(expr, prof_input)
split <- match.arg(split)
c(expr_q, env) %<-% enquo0_list(expr)

if (is.null(prof_input) && is.null(expr_q)) {
stop("profvis must be called with `expr` or `prof_input` ")
}
if (!is.null(prof_input) && (!is.null(expr_q) && !is.null(prof_output))) {
stop("The `prof_input` argument cannot be used with `expr` or `prof_output`.")
}

if (interval < 0.005) {
message("Intervals smaller than ~5ms will probably not result in accurate timings.")
}
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/profvis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# expr and prof_input are mutually exclusive

Code
profvis(expr = f(), prof_input = "foo.R")
Condition
Error in `profvis()`:
! Exactly one of `expr` or `prof_input` must be supplied.

4 changes: 4 additions & 0 deletions tests/testthat/test-profvis.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ test_that("defaults to elapsed timing", {
out <- repro_profvis(f(), rerun = "Sys.sleep")
expect_equal(profile_mode(out), "Sys.sleep f")
})

test_that("expr and prof_input are mutually exclusive", {
expect_snapshot(profvis(expr = f(), prof_input = "foo.R"), error = TRUE)
})

0 comments on commit f1b5d50

Please sign in to comment.