Skip to contents

Display diff of object definitions

Usage

construct_diff(
  target,
  current,
  ...,
  data = NULL,
  pipe = NULL,
  check = TRUE,
  compare = compare_options(),
  one_liner = FALSE,
  template = getOption("constructive_opts_template"),
  mode = c("sidebyside", "auto", "unified", "context"),
  interactive = TRUE
)

Arguments

target

the reference object

current

the object being compared to target

...

Constructive options built with the opts_*() family of functions. See the "Constructive options" section below.

data

Named list or environment of objects we want to detect and mention by name (as opposed to deparsing them further). Can also contain unnamed nested lists, environments, or package names, in the latter case package exports and datasets will be considered. In case of conflict, the last provided name is considered.

pipe

Which pipe to use, either "base" or "magrittr". Defaults to "base" for R >= 4.2, otherwise to "magrittr".

check

Boolean. Whether to check if the created code reproduces the object using waldo::compare().

compare

Parameters passed to waldo::compare(), built with compare_options().

one_liner

Boolean. Whether to collapse the output to a single line of code.

template

A list of constructive options built with opts_*() functions, they will be overriden by .... Use it to set a default behavior for {constructive}.

mode, interactive

passed to diffobj::diffChr()

Value

Returns NULL invisibly, called for side effects

Examples

if (FALSE) {
# some object print the same though they're different
# `construct_diff()` shows how they differ :
df1 <- data.frame(a=1, b = "x")
df2 <- data.frame(a=1L, b = "x", stringsAsFactors = TRUE)
attr(df2, "some_attribute") <- "a value"
df1
df2
construct_diff(df1, df2)


# Those are made easy to compare
construct_diff(substr, substring)
construct_diff(month.abb, month.name)

# more examples borrowed from {waldo} package
construct_diff(c("a", "b", "c"), c("a", "B", "c"))
construct_diff(c("X", letters), c(letters, "X"))
construct_diff(list(factor("x")), list(1L))
construct_diff(df1, df2)
x <- list(a = list(b = list(c = list(structure(1, e = 1)))))
y <- list(a = list(b = list(c = list(structure(1, e = "a")))))
construct_diff(x, y)
}