% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/compare_file_object.R
\name{compare_file_object}
\alias{compare_file_object}
\title{Compare RDS files using waldo for better snapshot review}
\usage{
compare_file_object(old, new, print = FALSE, ...)
}
\arguments{
\item{old}{Path to the old (reference) RDS file}

\item{new}{Path to the new RDS file to compare}

\item{print}{\link{logical} whether to print \link[waldo:compare]{waldo::compare} output to R console;
can become very long for complex objects like \link{lm}s}

\item{...}{
  Arguments passed on to \code{\link[waldo:compare]{waldo::compare}}
  \describe{
    \item{\code{x,y}}{Objects to compare. \code{x} is treated as the reference object
so messages describe how \code{y} is different to \code{x}.}
    \item{\code{x_arg,y_arg}}{Name of \code{x} and \code{y} arguments, used when generated paths
to internal components. These default to "old" and "new" since it's
most natural to supply the previous value then the new value.}
    \item{\code{tolerance}}{If non-\code{NULL}, used as threshold for ignoring small
floating point difference when comparing numeric vectors. Using any
non-\code{NULL} value will cause integer and double vectors to be compared
based on their values, not their types, and will ignore the difference
between \code{NaN} and \code{NA_real_}.

It uses the same algorithm as \code{\link[=all.equal]{all.equal()}}, i.e., first we generate
\code{x_diff} and \code{y_diff} by subsetting \code{x} and \code{y} to look only locations
with differences. Then we check that
\code{mean(abs(x_diff - y_diff)) / mean(abs(y_diff))} (or just
\code{mean(abs(x_diff - y_diff))} if \code{y_diff} is small) is less than
\code{tolerance}.}
    \item{\code{max_diffs}}{Control the maximum number of differences shown. The
default shows 10 differences when run interactively and all differences
when run in CI. Set \code{max_diffs = Inf} to see all differences.}
    \item{\code{ignore_srcref}}{Ignore differences in function \code{srcref}s? \code{TRUE} by
default since the \code{srcref} does not change the behaviour of a function,
only its printed representation.}
    \item{\code{ignore_attr}}{Ignore differences in specified attributes?
Supply a character vector to ignore differences in named attributes.
By default the \code{"waldo_opts"} attribute is listed in \code{ignore_attr} so
that changes to it are not reported; if you customize \code{ignore_attr}, you
will probably want to do this yourself.

For backward compatibility with \code{all.equal()}, you can also use \code{TRUE},
to all ignore differences in all attributes. This is not generally
recommended as it is a blunt tool that will ignore many important
functional differences.}
    \item{\code{ignore_encoding}}{Ignore string encoding? \code{TRUE} by default, because
this is R's default behaviour. Use \code{FALSE} when specifically concerned
with the encoding, not just the value of the string.}
    \item{\code{ignore_function_env,ignore_formula_env}}{Ignore the environments of
functions and formulas, respectively? These are provided primarily for
backward compatibility with \code{all.equal()} which always ignores these
environments.}
    \item{\code{list_as_map}}{Compare lists as if they are mappings between names and
values. Concretely, this drops \code{NULL}s in both objects and sorts named
components.}
    \item{\code{quote_strings}}{Should strings be surrounded by quotes? If \code{FALSE},
only side-by-side and line-by-line comparisons will be used, and there's
no way to distinguish between \code{NA} and \code{"NA"}.}
  }}
}
\value{
\link{logical} TRUE if objects are identical, FALSE otherwise
}
\description{
This comparison function loads RDS files and compares the deserialized
R objects rather than raw bytes. This enables better visualization in
snapshot_review() by comparing the actual object structure rather than
binary serialization.

For meaningful diffs in testthat's snapshot_review(), this function
compares the R objects after deserialization using \code{\link[waldo:compare]{waldo::compare()}}.
}
\examples{
old_obj <- list(a = 1, b = 2)
new_obj <- list(a = 1, b = 3)
old_path <- tempfile(fileext = ".rds")
new_path <- tempfile(fileext = ".rds")
saveRDS(old_obj, old_path)
saveRDS(new_obj, new_path)
compare_file_object(old_path, new_path)
}
