Skip to content

Commit

Permalink
Fix #214
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasp85 committed Nov 2, 2023
1 parent 2e8d601 commit 60a4ca1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* The `scale_cut` argument in `number()` now works as advertised for values
below the lowest cut value (#346)
* `label_dollar()` has been superseeded by `label_currency()` for clarity (#344)
* `sqrt_trans()` no longer returns an inverse for values outside of its domain
(#214)

# scales 1.2.1

Expand Down
2 changes: 1 addition & 1 deletion R/trans-numeric.R
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ sqrt_trans <- function() {
trans_new(
"sqrt",
"sqrt",
function(x) x^2,
function(x) ifelse(x < 0, NA_real_, x ^ 2),
domain = c(0, Inf)
)
}
4 changes: 4 additions & 0 deletions tests/testthat/test-trans.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ test_that("trans has useful print method", {
trans_new("test", transform = identity, inverse = identity)
})
})

test_that("inverse of trans_sqrt() returns NA for values outside of range", {
expect_equal(sqrt_trans()$inverse(-2), NA_real_)
})

0 comments on commit 60a4ca1

Please sign in to comment.