1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/compare.R
\name{compare}
\alias{compare}
\alias{compare.default}
\alias{compare.character}
\alias{compare.numeric}
\alias{compare.POSIXt}
\title{Provide human-readable comparison of two objects}
\usage{
compare(x, y, ...)
\method{compare}{default}(x, y, ..., max_diffs = 9)
\method{compare}{character}(
x,
y,
check.attributes = TRUE,
...,
max_diffs = 5,
max_lines = 5,
width = cli::console_width()
)
\method{compare}{numeric}(
x,
y,
tolerance = testthat_tolerance(),
check.attributes = TRUE,
...,
max_diffs = 9
)
\method{compare}{POSIXt}(x, y, tolerance = 0.001, ..., max_diffs = 9)
}
\arguments{
\item{x, y}{Objects to compare}
\item{...}{Additional arguments used to control specifics of comparison}
\item{max_diffs}{Maximum number of differences to show}
\item{check.attributes}{If \code{TRUE}, also checks values of attributes.}
\item{max_lines}{Maximum number of lines to show from each difference}
\item{width}{Width of output device}
\item{tolerance}{Numerical tolerance: any differences (in the sense of
\code{\link[base:all.equal]{base::all.equal()}}) smaller than this value will be ignored.
The default tolerance is \code{sqrt(.Machine$double.eps)}, unless long doubles
are not available, in which case the test is skipped.}
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}}
\code{compare} is similar to \code{\link[base:all.equal]{base::all.equal()}}, but somewhat buggy in its
use of \code{tolerance}. Please use \href{https://waldo.r-lib.org/}{waldo} instead.
}
\examples{
# Character -----------------------------------------------------------------
x <- c("abc", "def", "jih")
compare(x, x)
y <- paste0(x, "y")
compare(x, y)
compare(letters, paste0(letters, "-"))
x <- "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis cursus
tincidunt auctor. Vestibulum ac metus bibendum, facilisis nisi non, pulvinar
dolor. Donec pretium iaculis nulla, ut interdum sapien ultricies a. "
y <- "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis cursus
tincidunt auctor. Vestibulum ac metus1 bibendum, facilisis nisi non, pulvinar
dolor. Donec pretium iaculis nulla, ut interdum sapien ultricies a. "
compare(x, y)
compare(c(x, x), c(y, y))
# Numeric -------------------------------------------------------------------
x <- y <- runif(100)
y[sample(100, 10)] <- 5
compare(x, y)
x <- y <- 1:10
x[5] <- NA
x[6] <- 6.5
compare(x, y)
# Compare ignores minor numeric differences in the same way
# as all.equal.
compare(x, x + 1e-9)
}
\keyword{internal}
|