patch: patch

Description Usage Arguments Examples

Description

Patching related methods.

Generate a patch for two atomic objects that are close in values.

This patch will use another patch to record changes to attributes (if any). Otherwise, given indices of changed object, it will generate a patch over those indices.

Assume two objects are identical and only patch their attributes.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
as.patch(x)

identity_patch()

trivial_patch(object)

atomic_differences_patch(old_object, new_object, transition = TRUE)

differences_patch(old_object, new_object, differences)

attributes_patch(old_object, new_object)

Arguments

x

function. Apply patch class.

object

ANY. An R object that will be returned by the function created from trivial_patch. This is equivalent to "create a function that does nothing except return this object".

old_object

atomic.

new_object

atomic.

transition

logical. Whether or not to use a transition depending on how many element do not match. Namely, if over 50 from a random sample of 100 elements (so most of new_object is probably different than old_object) then replace it completely with a trivial patch; otherwise, perform a more subtle calculation using base::!= and stores only exactly which elements changed.

differences

logical or integer. The differences in first and second object. These should be calculated externally because a different approach could be used for different objects (e.g., lists versus atomic; in the former we would need base::identical on each element, whereas in the latter we could use base::`!=`).

Examples

1
2
3
x <- 1:10; y <- x; y[1] <- 5
patch <- objectdiff:::atomic_differences_patch(x, y) 
stopifnot(identical(y, patch(x)))

robertzk/objectdiff documentation built on May 27, 2019, 10:35 a.m.