Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix trailing "." when using format_sigfig, add functionality for multiple values #1067

Merged
merged 7 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
* Updated `add_rowcounts` to allow addition of row counts from `alt_counts_df` using the `alt_counts` argument.
* Added `gp` argument to `g_forest` to control graphical parameters such as font size.

### Bug Fixes
* Fixed bug in `format_sigfig` causing some numbers to be printed with trailing "." character.
edelarua marked this conversation as resolved.
Show resolved Hide resolved

### Miscellaneous
* Grouped functions relating to valid method names and their default formats and labels into new source file `utils_defaults_handling.R`.
* Started deprecation of `summary_custom()` and `a_summary()` as a `S3` method.
Expand Down
3 changes: 2 additions & 1 deletion R/formatting_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ format_sigfig <- function(sigfig) {
checkmate::assert_integerish(sigfig)
function(x, ...) {
if (!is.numeric(x)) stop("`format_sigfig` cannot be used for non-numeric values. Please choose another format.")
formatC(signif(x, digits = sigfig), digits = sigfig, format = "fg", flag = "#")
num <- formatC(signif(x, digits = sigfig), digits = sigfig, format = "fg", flag = "#")
gsub("\\.$", "", num) # remove trailing "."
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
Code
res
Output
[1] "1.66" "0.576" "0.100" "78.6" "0.00123"
[1] "1.66" "0.576" "0.100" "78.6" "0.00123" "200"

# format_fraction_threshold works with easy inputs

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-formats.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ testthat::test_that("format_xx works with easy inputs", {
})

testthat::test_that("format_sigfig works with easy inputs", {
test <- list(1.658, 0.5761, 1e-1, 78.6, 1234e-6)
test <- list(1.658, 0.5761, 1e-1, 78.6, 1234e-6, 200.00)
z <- format_sigfig(3)
result <- sapply(test, z)

Expand Down