The unidiff_dir() function compares files between two directories and generates unified diffs for each differing file. This function is useful for identifying and displaying differences between two directory structures, such as when comparing different versions of a codebase.

unidiff_dir(
  old,
  new,
  pattern = NULL,
  create_head = TRUE,
  with_context = FALSE,
  context_length = 3,
  ignore_whitespace = NULL,
  algorithm = "minimal",
  indent_heuristic = FALSE,
  ignore = NULL
)

Arguments

old

The directory path of the first directory to compare.

new

The directory path of the second directory to compare.

pattern

An optional regular expression. Only file names matching the pattern will be included in the comparison. Default is NULL, meaning all files are compared.

create_head

A logical flag (default TRUE) indicating whether to include a header in the diff output. The header contains the filenames or identifiers of the files being compared.

with_context

A logical flag (default FALSE) specifying whether to include the full context in the diff output. Including context helps to provide a more complete view of the changes.

context_length

An integer value (default 3) that determines the number of lines of context to include around each change. This is only relevant if with_context is TRUE.

ignore_whitespace

A character vector indicating how whitespace differences should be treated. Options include "all", "change", "at_eol", "cr_at_eol", and "blank_lines", allowing for fine-grained control over which whitespace differences to ignore.

algorithm

A string specifying the diff algorithm to use. Options are "minimal", "patience", and "histogram", with "minimal" being the default. Each algorithm has different characteristics suited to various types of text comparisons.

indent_heuristic

A logical flag (default FALSE) that, when enabled, applies an additional heuristic to better handle indented lines, improving the accuracy of the diff in some cases.

ignore

A single string specifying the regex pattern to use for ignoring lines in the diff process. If this is a non-empty string, it should be a valid regex pattern. Lines in the texts that match this pattern will be ignored in the diff.

Value

A character string containing the unified diffs for all differing files between the two directories.