-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enabled custom specification of binning decimal places by the use of …
…the binner_dp global option or BINNER_DP environment variable. Added relevant tests and documentation
- Loading branch information
jasenfinch
committed
Sep 1, 2021
1 parent
55160cb
commit e16927a
Showing
11 changed files
with
217 additions
and
63 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 |
---|---|---|
|
@@ -45,6 +45,7 @@ Collate: | |
readBinningParameters.R | ||
reexports.R | ||
access.R | ||
internals.R | ||
Suggests: | ||
knitr, | ||
rmarkdown, | ||
|
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,66 @@ | ||
|
||
binnerDPenv <- function(){ | ||
dp <- Sys.getenv('BINNER_DP') | ||
|
||
if (dp != '') { | ||
dp <- suppressWarnings(as.numeric(dp)) | ||
} else { | ||
dp <- 2 | ||
} | ||
|
||
if (is.na(dp)){ | ||
warning("The environment variable 'BINNER_DP' is not numeric. Using 2 decimal places instead.", | ||
call. = FALSE) | ||
dp <- 2 | ||
} | ||
|
||
if (dp > 5){ | ||
warning("The environment variable 'BINNER_DP' is greater than 5. Using 2 decimal places instead.", | ||
call. = FALSE) | ||
dp <- 2 | ||
} | ||
|
||
return(dp) | ||
} | ||
|
||
binnerDPopt <- function(){ | ||
dp <- options()$binner_dp | ||
|
||
if (is.null(dp)){ | ||
dp <- 2 | ||
} | ||
|
||
if (!is.numeric(dp)){ | ||
warning("The global option 'binner_dp' is not numeric. Using 2 decimal places instead.", | ||
call. = FALSE) | ||
dp <- 2 | ||
} | ||
|
||
if (dp > 5){ | ||
warning("The global option 'binner_dp' is greater than 5. Using 2 decimal places instead.", | ||
call. = FALSE) | ||
dp <- 2 | ||
} | ||
|
||
return(dp) | ||
} | ||
|
||
binnerDP <- function(){ | ||
|
||
dp_env <- binnerDPenv() | ||
|
||
dp_opt <- binnerDPopt() | ||
|
||
dp <- c(dp_opt, | ||
dp_env) %>% | ||
unique() | ||
|
||
if (length(dp) > 1) { | ||
warning("The environment variable 'BINNER_DP' and global option 'binner_dp' are differentially set. Using the value of 'binner_dp'.", | ||
call. = FALSE) | ||
|
||
dp <- dp[1] | ||
} | ||
|
||
return(dp) | ||
} |
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
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,58 @@ | ||
|
||
test_that("setting BINNER_DP works", { | ||
Sys.setenv(BINNER_DP = 3) | ||
|
||
expect_equal(binnerDPenv(),3) | ||
|
||
Sys.unsetenv('BINNER_DP') | ||
}) | ||
|
||
test_that("warning thrown when BINNER_DP set above 5", { | ||
Sys.setenv(BINNER_DP = 6) | ||
|
||
expect_warning(binnerDPenv()) | ||
|
||
Sys.unsetenv('BINNER_DP') | ||
}) | ||
|
||
test_that("warning thrown when BINNER_DP set as non-numeric", { | ||
Sys.setenv(BINNER_DP = 'a') | ||
|
||
expect_warning(binnerDPenv()) | ||
|
||
Sys.unsetenv('BINNER_DP') | ||
}) | ||
|
||
test_that("setting binner_dp works", { | ||
options(binner_dp = 3) | ||
|
||
expect_equal(binnerDPopt(),3) | ||
|
||
options(binner_dp = NULL) | ||
}) | ||
|
||
test_that("warning thrown when binner_dp set above 5", { | ||
options(binner_dp = 6) | ||
|
||
expect_warning(binnerDPopt()) | ||
|
||
options(binner_dp = NULL) | ||
}) | ||
|
||
test_that("warning thrown when binner_dp set as non-numeric", { | ||
options(binner_dp = 'a') | ||
|
||
expect_warning(binnerDPopt()) | ||
|
||
options(binner_dp = NULL) | ||
}) | ||
|
||
test_that("warning thrown when BINNER_DP and binner_dp are differentially set", { | ||
options(binner_dp = 3) | ||
Sys.setenv(BINNER_DP = 4) | ||
|
||
expect_warning(binnerDP()) | ||
|
||
options(binner_dp = NULL) | ||
Sys.unsetenv('BINNER_DP') | ||
}) |