Its printed output is similar to calling diff -u at the command
line.
Arguments
- old
First character vector.
- new
Second character vector.
- max_dist
Maximum distance to consider, or
Inffor no limit. If the LCS edit distance is larger than this, then the function throws an error with class"cli_diff_max_dist". (If you specifyInfthe real limit is.Machine$integer.maxbut to reach this the function would have to run a very long time.)
Value
A list that is a cli_diff_chr object, with a format() and a
print() method. You can also access its members:
oldandneware the original inputs,lcsis a data frame of LCS edit that transformoldintonew.
The lcs data frame has the following columns:
operation: one of"match","delete"or"insert".offset: offset inoldfor matches and deletions, offset innewfor insertions.length: length of the operation, i.e. number of matching, deleted or inserted elements.old_offset: offset inoldafter the operation.new_offset: offset innewafter the operation.
See also
The diffobj package for a much more comprehensive set of
diff-like tools.
Other diff functions in cli:
diff_str()
Examples
letters2 <- c("P", "R", "E", letters, "P", "O", "S", "T")
letters2[11:16] <- c("M", "I", "D", "D", "L", "E")
diff_chr(letters, letters2)
#> @@ -1,3 +1,6 @@
#> +P
#> +R
#> +E
#> a
#> b
#> c
#> @@ -5,12 +8,12 @@
#> e
#> f
#> g
#> -h
#> -i
#> -j
#> -k
#> -l
#> -m
#> +M
#> +I
#> +D
#> +D
#> +L
#> +E
#> n
#> o
#> p
#> @@ -24,3 +27,7 @@
#> x
#> y
#> z
#> +P
#> +O
#> +S
#> +T