1% Generated by roxygen2: do not edit by hand 2% Please edit documentation in R/diff.R 3\name{diffCsv} 4\alias{diffCsv} 5\alias{diffCsv,ANY-method} 6\title{Diff CSV Files} 7\usage{ 8diffCsv(target, current, ...) 9 10\S4method{diffCsv}{ANY}( 11 target, 12 current, 13 mode = gdo("mode"), 14 context = gdo("context"), 15 format = gdo("format"), 16 brightness = gdo("brightness"), 17 color.mode = gdo("color.mode"), 18 word.diff = gdo("word.diff"), 19 pager = gdo("pager"), 20 guides = gdo("guides"), 21 trim = gdo("trim"), 22 rds = gdo("rds"), 23 unwrap.atomic = gdo("unwrap.atomic"), 24 max.diffs = gdo("max.diffs"), 25 disp.width = gdo("disp.width"), 26 ignore.white.space = gdo("ignore.white.space"), 27 convert.hz.white.space = gdo("convert.hz.white.space"), 28 tab.stops = gdo("tab.stops"), 29 line.limit = gdo("line.limit"), 30 hunk.limit = gdo("hunk.limit"), 31 align = gdo("align"), 32 style = gdo("style"), 33 palette.of.styles = gdo("palette"), 34 frame = par_frame(), 35 interactive = gdo("interactive"), 36 term.colors = gdo("term.colors"), 37 tar.banner = NULL, 38 cur.banner = NULL, 39 strip.sgr = gdo("strip.sgr"), 40 sgr.supported = gdo("sgr.supported"), 41 extra = list() 42) 43} 44\arguments{ 45\item{target}{character(1L) or file connection with read capability; 46if character should point to a CSV file} 47 48\item{current}{like \code{target}} 49 50\item{...}{unused, for compatibility of methods with generics} 51 52\item{mode}{character(1L), one of: 53\itemize{ 54 \item \dQuote{unified}: diff mode used by \code{git diff} 55 \item \dQuote{sidebyside}: line up the differences side by side 56 \item \dQuote{context}: show the target and current hunks in their 57 entirety; this mode takes up a lot of screen space but makes it easier 58 to see what the objects actually look like 59 \item \dQuote{auto}: default mode; pick one of the above, will favor 60 \dQuote{sidebyside} unless \code{getOption("width")} is less than 80, 61 or in \code{diffPrint} and objects are dimensioned and do not fit side 62 by side, or in \code{diffChr}, \code{diffDeparse}, \code{diffFile} and 63 output does not fit in side by side without wrapping 64}} 65 66\item{context}{integer(1L) how many lines of context are shown on either side 67of differences (defaults to 2). Set to \code{-1L} to allow as many as 68there are. Set to \dQuote{auto} to display as many as 10 lines or as few 69as 1 depending on whether total screen lines fit within the number of lines 70specified in \code{line.limit}. Alternatively pass the return value of 71\code{\link{auto_context}} to fine tune the parameters of the auto context 72calculation.} 73 74\item{format}{character(1L), controls the diff output format, one of: 75\itemize{ 76 \item \dQuote{auto}: to select output format based on terminal 77 capabilities; will attempt to use one of the ANSI formats if they 78 appear to be supported, and if not or if you are in the Rstudio console 79 it will attempt to use HTML and browser output if in interactive mode. 80 \item \dQuote{raw}: plain text 81 \item \dQuote{ansi8}: color and format diffs using basic ANSI escape 82 sequences 83 \item \dQuote{ansi256}: like \dQuote{ansi8}, except using the full range 84 of ANSI formatting options 85 \item \dQuote{html}: color and format using HTML markup; the resulting 86 string is processed with \code{\link{enc2utf8}} when output as a full 87 web page (see docs for \code{html.output} under \code{\link{Style}}). 88} 89Defaults to \dQuote{auto}. See \code{palette.of.styles} for details 90on customization, \code{\link{style}} for full control of output format. 91See `pager` parameter for more discussion of Rstudio behavior.} 92 93\item{brightness}{character, one of \dQuote{light}, \dQuote{dark}, 94\dQuote{neutral}, useful for adjusting color scheme to light or dark 95terminals. \dQuote{neutral} by default. See \code{\link{PaletteOfStyles}} 96for details and limitations. Advanced: you may specify brightness as a 97function of \code{format}. For example, if you typically wish to use a 98\dQuote{dark} color scheme, except for when in \dQuote{html} format when 99you prefer the \dQuote{light} scheme, you may use 100\code{c("dark", html="light")} as the value for this parameter. This is 101particularly useful if \code{format} is set to \dQuote{auto} or if you 102want to specify a default value for this parameter via options. Any names 103you use should correspond to a \code{format}. You must have one unnamed 104value which will be used as the default for all \code{format}s that are 105not explicitly specified.} 106 107\item{color.mode}{character, one of \dQuote{rgb} or \dQuote{yb}. 108Defaults to \dQuote{yb}. \dQuote{yb} stands for \dQuote{Yellow-Blue} for 109color schemes that rely primarily on those colors to style diffs. 110Those colors can be easily distinguished by individuals with 111limited red-green color sensitivity. See \code{\link{PaletteOfStyles}} for 112details and limitations. Also offers the same advanced usage as the 113\code{brightness} parameter.} 114 115\item{word.diff}{TRUE (default) or FALSE, whether to run a secondary word 116diff on the in-hunk differences. For atomic vectors setting this to 117FALSE could make the diff \emph{slower} (see the \code{unwrap.atomic} 118parameter). For other uses, particularly with \code{\link{diffChr}} 119setting this to FALSE can substantially improve performance.} 120 121\item{pager}{one of \dQuote{auto} (default), \dQuote{on}, 122 \dQuote{off}, a \code{\link{Pager}} object, or a list; controls whether and 123 how a pager is used to display the diff output. If you require a 124 particular pager behavior you must use a \code{\link{Pager}} 125 object, or \dQuote{off} to turn off the pager. All other settings will 126 interact with other parameters such as \code{format}, \code{style}, as well 127 as with your system capabilities in order to select the pager expected to 128 be most useful. 129 130 \dQuote{auto} and \dQuote{on} are the same, except that in non-interactive 131 mode \dQuote{auto} is equivalent to \dQuote{off}. \dQuote{off} will always 132 send output to the console. If \dQuote{on}, whether the output 133 actually gets routed to the pager depends on the pager \code{threshold} 134 setting (see \code{\link{Pager}}). The default behavior is to use the 135 pager associated with the \code{Style} object. The \code{Style} object is 136 itself is determined by the \code{format} or \code{style} parameters. 137 138 Depending on your system configuration different styles and corresponding 139 pagers will get selected, unless you specify a \code{Pager} object 140 directly. On a system with a system pager that supports ANSI CSI SGR 141 colors, the pager will only trigger if the output is taller than one 142 window. If the system pager is not known to support ANSI colors then the 143 output will be sent as HTML to the IDE viewer if available or to the web 144 browser if not. Even though Rstudio now supports ANSI CSI SGR at the 145 console output is still formatted as HTML and sent to the IDE viewer. 146 Partly this is for continuity of behavior, but also because the default 147 Rstudio pager does not support ANSI CSI SGR, at least as of this writing. 148 149 If \code{pager} is a list, then the same as with \dQuote{on}, except that 150 the \code{Pager} object associated with the selected \code{Style} object is 151 re-instantiated with the union of the list elements and the existing 152 settings of that \code{Pager}. The list should contain named elements that 153 correspond to the \code{\link{Pager}} instantiation parameters. The names 154 must be specified in full as partial parameter matching will not be carried 155 out because the pager is re-instantiated with \code{\link{new}}. 156 157 See \code{\link{Pager}}, \code{\link{Style}}, and 158 \code{\link{PaletteOfStyles}} for more details and for instructions on how 159 to modify the default behavior.} 160 161\item{guides}{TRUE (default), FALSE, or a function that accepts at least two 162arguments and requires no more than two arguments. Guides 163are additional context lines that are not strictly part of a hunk, but 164provide important contextual data (e.g. column headers). If TRUE, the 165context lines are shown in addition to the normal diff output, typically 166in a different color to indicate they are not part of the hunk. If a 167function, the function should accept as the first argument the object 168being diffed, and the second the character representation of the object. 169The function should return the indices of the elements of the 170character representation that should be treated as guides. See 171\code{\link{guides}} for more details.} 172 173\item{trim}{TRUE (default), FALSE, or a function that accepts at least two 174arguments and requires no more than two arguments. Function should compute 175for each line in captured output what portion of those lines should be 176diffed. By default, this is used to remove row meta data differences 177(e.g. \code{[1,]}) so they alone do not show up as differences in the 178diff. See \code{\link{trim}} for more details.} 179 180\item{rds}{TRUE (default) or FALSE, if TRUE will check whether 181\code{target} and/or \code{current} point to a file that can be read with 182\code{\link{readRDS}} and if so, loads the R object contained in the file 183and carries out the diff on the object instead of the original argument. 184Currently there is no mechanism for specifying additional arguments to 185\code{readRDS}} 186 187\item{unwrap.atomic}{TRUE (default) or FALSE. Relevant primarily for 188\code{diffPrint}, if TRUE, and \code{word.diff} is also TRUE, and both 189\code{target} and \code{current} are \emph{unnamed} one-dimension atomics , 190the vectors are unwrapped and diffed element by element, and then 191re-wrapped. Since \code{diffPrint} is fundamentally a line diff, the 192re-wrapped lines are lined up in a manner that is as consistent as possible 193with the unwrapped diff. Lines that contain the location of the word 194differences will be paired up. Since the vectors may well be wrapped with 195different periodicities this will result in lines that are paired up that 196look like they should not be paired up, though the locations of the 197differences should be. If is entirely possible that setting this parameter 198to FALSE will result in a slower diff. This happens if two vectors are 199actually fairly similar, but their line representations are not. For 200example, in comparing \code{1:100} to \code{c(100, 1:99)}, there is really 201only one difference at the \dQuote{word} level, but every screen line is 202different. \code{diffChr} will also do the unwrapping if it is given a 203character vector that contains output that looks like the atomic vectors 204described above. This is a bug, but as the functionality could be useful 205when diffing e.g. \code{capture.output} data, we now declare it a feature.} 206 207\item{max.diffs}{integer(1L), number of \emph{differences} (default 50000L) 208after which we abandon the \code{O(n^2)} diff algorithm in favor of a naive 209\code{O(n)} one. Set to \code{-1L} to stick to the original algorithm up to 210the maximum allowed (~INT_MAX/4).} 211 212\item{disp.width}{integer(1L) number of display columns to take up; note that 213in \dQuote{sidebyside} \code{mode} the effective display width is half this 214number (set to 0L to use default widths which are \code{getOption("width")} 215for normal styles and \code{80L} for HTML styles. Future versions of 216\code{diffobj} may change this to larger values for two dimensional objects 217for better diffs (see details).} 218 219\item{ignore.white.space}{TRUE or FALSE, whether to consider differences in 220horizontal whitespace (i.e. spaces and tabs) as differences (defaults to 221TRUE).} 222 223\item{convert.hz.white.space}{TRUE or FALSE, whether modify input strings 224that contain tabs and carriage returns in such a way that they display as 225they would \bold{with} those characters, but without using those 226characters (defaults to TRUE). The conversion assumes that tab stops are 227spaced evenly eight characters apart on the terminal. If this is not the 228case you may specify the tab stops explicitly with \code{tab.stops}.} 229 230\item{tab.stops}{integer, what tab stops to use when converting hard tabs to 231spaces. If not integer will be coerced to integer (defaults to 8L). You 232may specify more than one tab stop. If display width exceeds that 233addressable by your tab stops the last tab stop will be repeated.} 234 235\item{line.limit}{integer(2L) or integer(1L), if length 1 how many lines of 236output to show, where \code{-1} means no limit. If length 2, the first 237value indicates the threshold of screen lines to begin truncating output, 238and the second the number of lines to truncate to, which should be fewer 239than the threshold. Note that this parameter is implemented on a 240best-efforts basis and should not be relied on to produce the exact 241number of lines requested. In particular do not expect it to work well for 242for values small enough that the banner portion of the diff would have to 243be trimmed. If you want a specific number of lines use \code{[} or 244\code{head} / \code{tail}. One advantage of \code{line.limit} over these 245other options is that you can combine it with \code{context="auto"} and 246auto \code{max.level} selection (the latter for \code{diffStr}), which 247allows the diff to dynamically adjust to make best use of the available 248display lines. \code{[}, \code{head}, and \code{tail} just subset the text 249of the output.} 250 251\item{hunk.limit}{integer(2L) or integer (1L), how many diff hunks to show. 252Behaves similarly to \code{line.limit}. How many hunks are in a 253particular diff is a function of how many differences, and also how much 254\code{context} is used since context can cause two hunks to bleed into 255each other and become one.} 256 257\item{align}{numeric(1L) between 0 and 1, proportion of 258words in a line of \code{target} that must be matched in a line of 259\code{current} in the same hunk for those lines to be paired up when 260displayed (defaults to 0.25), or an \code{\link{AlignThreshold}} object. 261Set to \code{1} to turn off alignment which will cause all lines in a hunk 262from \code{target} to show up first, followed by all lines from 263\code{current}. Note that in order to be aligned lines must meet the 264threshold and have at least 3 matching alphanumeric characters (see 265\code{\link{AlignThreshold}} for details).} 266 267\item{style}{\dQuote{auto}, a \code{\link{Style}} object, or a list. 268\dQuote{auto} by default. If a \code{Style} object, will override the 269the \code{format}, \code{brightness}, and \code{color.mode} parameters. 270The \code{Style} object provides full control of diff output styling. 271If a list, then the same as \dQuote{auto}, except that if the auto-selected 272\code{Style} requires instantiation (see \code{\link{PaletteOfStyles}}), 273then the list contents will be used as arguments when instantiating the 274style object. See \code{\link{Style}} for more details, in particular the 275examples.} 276 277\item{palette.of.styles}{\code{\link{PaletteOfStyles}} object; advanced 278usage, contains all the \code{\link{Style}} objects or 279\dQuote{classRepresentation} objects extending \code{\link{Style}} that are 280selected by specifying the \code{format}, \code{brightness}, and 281\code{color.mode} parameters. See \code{\link{PaletteOfStyles}} for more 282details.} 283 284\item{frame}{an environment to use as the evaluation frame for the 285\code{print/show/str}, calls and for \code{diffObj}, the evaluation frame 286for the \code{diffPrint} / \code{diffStr} calls. Defaults to the return 287value of \code{\link{par_frame}}.} 288 289\item{interactive}{TRUE or FALSE whether the function is being run in 290interactive mode, defaults to the return value of 291\code{\link{interactive}}. If in interactive mode, pager will be used if 292\code{pager} is \dQuote{auto}, and if ANSI styles are not supported and 293\code{style} is \dQuote{auto}, output will be send to viewer/browser as 294HTML.} 295 296\item{term.colors}{integer(1L) how many ANSI colors are supported by the 297terminal. This variable is provided for when 298\code{\link[=num_colors]{crayon::num_colors}} does not properly detect how 299many ANSI colors are supported by your terminal. Defaults to return value 300of \code{\link[=num_colors]{crayon::num_colors}} and should be 8 or 256 to 301allow ANSI colors, or any other number to disallow them. This only 302impacts output format selection when \code{style} and \code{format} are 303both set to \dQuote{auto}.} 304 305\item{tar.banner}{character(1L), language, or NULL, used to generate the 306text to display ahead of the diff section representing the target output. 307If NULL will use the deparsed \code{target} expression, if language, will 308use the language as it would the \code{target} expression, if 309character(1L), will use the string with no modifications. The language 310mode is provided because \code{diffStr} modifies the expression prior to 311display (e.g. by wrapping it in a call to \code{str}). Note that it is 312possible in some cases that the substituted value of \code{target} actually 313is character(1L), but if you provide a character(1L) value here it will be 314assumed you intend to use that value literally.} 315 316\item{cur.banner}{character(1L) like \code{tar.banner}, but for 317\code{current}} 318 319\item{strip.sgr}{TRUE, FALSE, or NULL (default), whether to strip ANSI CSI 320SGR sequences prior to comparison and for display of diff. If NULL, 321resolves to TRUE if `style` resolves to an ANSI formatted diff, and 322FALSE otherwise. The default behavior is to avoid confusing diffs where 323the original SGR and the SGR added by the diff are mixed together.} 324 325\item{sgr.supported}{TRUE, FALSE, or NULL (default), whether to assume the 326standard output device supports ANSI CSI SGR sequences. If TRUE, strings 327will be manipulated accounting for the SGR sequences. If NULL, 328resolves to TRUE if `style` resolves to an ANSI formatted diff, and 329to `crayon::has_color()` otherwise. This only controls how the strings are 330manipulated, not whether SGR is added to format the diff, which is 331controlled by the `style` parameter. This parameter is exposed for the 332rare cases where you might wish to control string manipulation behavior 333directly.} 334 335\item{extra}{list additional arguments to pass on to the functions used to 336create text representation of the objects to diff (e.g. \code{print}, 337\code{str}, etc.)} 338} 339\value{ 340a \code{Diff} object; see \code{\link{diffPrint}}. 341} 342\description{ 343Reads CSV files with \code{\link{read.csv}} and passes the resulting data 344frames onto \code{\link{diffPrint}}. \code{extra} values are passed as 345arguments are passed to both \code{read.csv} and \code{print}. To the 346extent you wish to use different \code{extra} arguments for each of those 347functions you will need to \code{read.csv} the files and pass them to 348\code{diffPrint} yourself. 349} 350\examples{ 351iris.2 <- iris 352iris.2$Sepal.Length[5] <- 99 353f1 <- tempfile() 354f2 <- tempfile() 355write.csv(iris, f1, row.names=FALSE) 356write.csv(iris.2, f2, row.names=FALSE) 357## `pager="off"` for CRAN compliance; you may omit in normal use 358diffCsv(f1, f2, pager="off") 359unlink(c(f1, f2)) 360} 361\seealso{ 362\code{\link{diffPrint}} for details on the \code{diff*} functions, 363 \code{\link{diffObj}}, \code{\link{diffStr}}, 364 \code{\link{diffChr}} to compare character vectors directly, 365 \code{\link{ses}} for a minimal and fast diff 366} 367