forked from tidyverse/dplyr
-
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.
Fixes tidyverse#1607.
- Loading branch information
Showing
6 changed files
with
47 additions
and
0 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 |
---|---|---|
|
@@ -76,6 +76,7 @@ Collate: | |
'lead-lag.R' | ||
'location.R' | ||
'manip.r' | ||
'near.R' | ||
'nth-value.R' | ||
'order-by.R' | ||
'over.R' | ||
|
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,15 @@ | ||
#' Compare two numeric vectors. | ||
#' | ||
#' This is a safe way of comparing if two vectors of floating point numbers | ||
#' are (pairwise) equal. This is safer than using \code{==}, because it has | ||
#' a built in tolerance | ||
#' | ||
#' @param x,y Numeric vectors to compare | ||
#' @param tol Tolerance of comparison. | ||
#' @export | ||
#' @examples | ||
#' sqrt(2) ^ 2 == 2 | ||
#' near(sqrt(2) ^ 2, 2) | ||
near <- function(x, y, tol = .Machine$double.eps ^ 0.5) { | ||
abs(x - y) < tol | ||
} |
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,5 @@ | ||
context("near") | ||
|
||
test_that("near accepts nearby fp values", { | ||
expect_true(near(sqrt(2) ^ 2, 2)) | ||
}) |