-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Eliminate `run_on_load()` helper * Use zzz.R * Add package doc and move imports there * Add some basic pause tests * Improve pause error checking
- Loading branch information
Showing
8 changed files
with
94 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +0,0 @@ | ||
#' @import rlang | ||
NULL | ||
|
||
.onLoad <- function(...) { | ||
run_on_load() | ||
} | ||
|
||
on_load <- function(expr, env = topenv(caller_env())) { | ||
callback <- function() eval_bare(expr, env) | ||
env$.__rlang_hook__. <- list2(!!!env$.__rlang_hook__., callback) | ||
} | ||
|
||
run_on_load <- function(env = topenv(caller_env())) { | ||
hook <- env$.__rlang_hook__. | ||
env_unbind(env, ".__rlang_hook__.") | ||
|
||
for (callback in hook) { | ||
callback() | ||
} | ||
|
||
env$.__rlang_hook__. <- NULL | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#' @keywords internal | ||
"_PACKAGE" | ||
|
||
## usethis namespace: start | ||
#' @import rlang | ||
## usethis namespace: end | ||
NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.onLoad <- function(...) { | ||
on_load_pause() | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# checks its inputs | ||
|
||
Code | ||
pause(c(1, 2)) | ||
Condition | ||
Error in `pause()`: | ||
! `seconds` must be a single number. | ||
Code | ||
pause("a") | ||
Condition | ||
Error in `pause()`: | ||
! `seconds` must be a single number. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
test_that("pause takes expected time", { | ||
time <- system.time(pause(0.2))[[3]] | ||
# system.time is a little inaccurate so allow 10% padding | ||
expect_true(abs(time - 0.2) < 1e-2) | ||
}) | ||
|
||
test_that("works with integers", { | ||
expect_no_error(pause(0L)) | ||
}) | ||
|
||
test_that("pause has no srcrefs", { | ||
expect_equal(attr(pause, "srcref"), NULL) | ||
}) | ||
|
||
test_that("checks its inputs", { | ||
expect_snapshot(error = TRUE, { | ||
pause(c(1, 2)) | ||
pause("a") | ||
}) | ||
}) |