-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
88 additions
and
9 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
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
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,28 @@ | ||
#' Local Timer | ||
#' | ||
#' @inheritParams params | ||
#' | ||
#' @return xx | ||
#' @export | ||
#' | ||
#' @examples | ||
#' local_timer() | ||
local_timer <- function(.local_envir = rlang::caller_env()) { | ||
chk_env(.local_envir) | ||
|
||
if(!requireNamespace("withr", quietly = TRUE)) { | ||
err("Package 'withr' must be installed to create a local_timer().") | ||
} | ||
|
||
tmr <- tmr_(seconds = 0, start = TRUE, caller = sys.call(-1)) | ||
withr::defer(message(tmr_format(tmr)), envir = .local_envir) | ||
invisible(tmr) | ||
} | ||
|
||
tmr_ <- function(seconds, start, caller = sys.call(-1)) { | ||
seconds <- as.double(seconds) | ||
|
||
x <- as_hms(seconds) | ||
if (start) x <- tmr_start(x) | ||
x | ||
} |
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,8 +1,10 @@ | ||
#' #' Parameter Descriptions for hmstimer Functions | ||
#' @param x A [hms_timer()]. | ||
#' Parameter Descriptions for hmstimer Functions | ||
#' | ||
#' @param .local_envir The environment to use for scoping | ||
#' @param digits A whole number of the number of decimal places. | ||
#' @param seconds A non-negative numeric scalar of the initial number of seconds. | ||
#' @param start A flag indicating whether to start the timer. | ||
#' @param digits A whole number of the number of decimal places. | ||
#' @param x A [hms_timer()]. | ||
#' @keywords internal | ||
#' @name params | ||
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,5 @@ | ||
test_local_timer <- function() { | ||
local_timer() | ||
Sys.sleep(0.1) | ||
NULL | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
test_that("local_timer", { | ||
fun <- function(x) { | ||
tmr <- local_timer() | ||
Sys.sleep(0.1) | ||
NULL | ||
} | ||
expect_message(fun(), "^00:00:00.1\\d{2,2}\\s$") | ||
}) | ||
|
||
test_that("test_local_timer()", { | ||
test_local_timer() | ||
}) |