hl_diff {emphatic}R Documentation

Colour the differences between character representations of objects

Description

Highlight the differences between two strings in terms of substitutions, insertions and deletions calculated by the generalized Levenshtein (edit) distance (using adist())

Usage

hl_diff(
  x,
  y,
  coerce = "default",
  fill = NULL,
  text = NULL,
  opts = hl_opts(),
  sep = NULL,
  ...
)

Arguments

x, y

each argument is a single string. vectors of strings not currently supported.

coerce

How should non-character arguments be coerced to character strings?

default

- the given object x must already be a character string

character

- performs the matching after first calling as.character(x)

print

- performs the matching against the default print(x) output

deparse

- performs the matching after first calling deparse1(x)

str

- performs the matching on the output of calling str(x)

fill

named list of colours for substitutions, insertions and deletions with names 'sub', 'ins' and 'del'. If set to NULL (the default) then default colours will be used.

text

named list of colours for the text for 'sub', 'ins' and 'del' operations. If NULL, then colours which contrast with fill will be chosen automatically

opts

create options list

sep

character string of the line separating the two objects. Default: NULL for no separation. Use the empty string to insert an empty line.

...

further arguments passed to adist()

Details

This works character-by-character, so the displayed difference for multiline strings can be quite busy if there are a lot of changes.

Value

list of 'emphatic' objects which could be rendered to ANSI (for example)

Examples

hl_diff('hello', 'there')

[Package emphatic version 0.1.8 Index]