-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add rnoaa_options function for handlling pkg level options
within rnoaa_options added cache_messages param setting to toggle messages added a test for rnoaa_options aaded message suppression handling in the four functions that currently use hoardr caching: cpc, arc2, lcd, bsw
- Loading branch information
Showing
13 changed files
with
94 additions
and
14 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
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,30 @@ | ||
roenv <- new.env() | ||
roenv$cache_messages <- TRUE | ||
|
||
#' rnoaa options | ||
#' @export | ||
#' @param cache_messages (logical) whether to emit messages with information | ||
#' on caching status for function calls that can cache data. default: `TRUE` | ||
#' @details rnoaa package level options; stored in an internal | ||
#' package environment `roenv` | ||
#' @examples \dontrun{ | ||
#' rnoaa_options(cache_messages = FALSE) | ||
#' } | ||
rnoaa_options <- function(cache_messages = TRUE) { | ||
roenv$cache_messages <- cache_messages | ||
return(NULL) | ||
} | ||
|
||
stract <- function(str, pattern) regmatches(str, regexpr(pattern, str)) | ||
|
||
cache_mssg <- function(file) { | ||
if (roenv$cache_messages) { | ||
fi <- file.info(file) | ||
size <- round(fi$size/1000000, 3) | ||
chaftdec <- nchar(stract(as.character(size), '^[0-9]+')) | ||
if (chaftdec > 1) size <- round(size, 1) | ||
message("using cached file: ", file) | ||
message( | ||
sprintf("date created/size(mb): %s / %s", fi$ctime, size)) | ||
} | ||
} |
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.
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,17 @@ | ||
# delete any cached files | ||
arc2_cache$delete_all() | ||
|
||
test_that("rnoaa_options", { | ||
skip_on_cran() | ||
|
||
expect_is(rnoaa_options, "function") | ||
expect_null(rnoaa_options()) | ||
|
||
# after setting param its in the env var | ||
expect_true(roenv$cache_messages) | ||
rnoaa_options(FALSE) | ||
expect_false(roenv$cache_messages) | ||
|
||
# reset options | ||
rnoaa_options() | ||
}) |