Commit 3b983164 authored by Andreas Tille's avatar Andreas Tille

New upstream version 0.2.2

parents
Package: diffobj
Type: Package
Title: Diffs for R Objects
Description: Generate a colorized diff of two R objects for an intuitive
visualization of their differences.
Version: 0.2.2
Authors@R: c(
person(
"Brodie", "Gaslam", email="brodie.gaslam@yahoo.com",
role=c("aut", "cre")),
person(
"Michael B.", "Allen", email="ioplex@gmail.com",
role=c("ctb", "cph"),
comment="Original C implementation of Myers Diff Algorithm"))
Depends: R (>= 3.1.0)
License: GPL (>= 2)
LazyData: true
URL: https://github.com/brodieG/diffobj
BugReports: https://github.com/brodieG/diffobj/issues
RoxygenNote: 6.1.0.9000
VignetteBuilder: knitr
Encoding: UTF-8
Suggests: knitr, rmarkdown, testthat
Collate: 'capt.R' 'options.R' 'pager.R' 'check.R' 'finalizer.R'
'misc.R' 'html.R' 'styles.R' 's4.R' 'core.R' 'diff.R' 'get.R'
'guides.R' 'hunks.R' 'layout.R' 'myerssimple.R' 'rdiff.R'
'rds.R' 'set.R' 'subset.R' 'summmary.R' 'system.R' 'text.R'
'tochar.R' 'trim.R' 'word.R'
Imports: crayon (>= 1.3.2), tools, methods, utils, stats
NeedsCompilation: yes
Packaged: 2019-03-15 01:48:48 UTC; bg
Author: Brodie Gaslam [aut, cre],
Michael B. Allen [ctb, cph] (Original C implementation of Myers Diff
Algorithm)
Maintainer: Brodie Gaslam <brodie.gaslam@yahoo.com>
Repository: CRAN
Date/Publication: 2019-03-15 19:03:48 UTC
This diff is collapsed.
# Generated by roxygen2: do not edit by hand
S3method(print,diffobj_ogewlhgiadfl)
export(AlignThreshold)
export(Pager)
export(PagerBrowser)
export(PagerOff)
export(PagerSystem)
export(PagerSystemLess)
export(PaletteOfStyles)
export(Rdiff_chr)
export(Rdiff_obj)
export(Style)
export(StyleAnsi)
export(StyleAnsi256DarkRgb)
export(StyleAnsi256DarkYb)
export(StyleAnsi256LightRgb)
export(StyleAnsi256LightYb)
export(StyleAnsi8NeutralRgb)
export(StyleAnsi8NeutralYb)
export(StyleFuns)
export(StyleHtml)
export(StyleHtmlLightRgb)
export(StyleHtmlLightYb)
export(StyleRaw)
export(StyleText)
export(auto_context)
export(console_lines)
export(cont_f)
export(diffChr)
export(diffCsv)
export(diffDeparse)
export(diffFile)
export(diffObj)
export(diffPrint)
export(diffStr)
export(diffobj_css)
export(diffobj_js)
export(diffobj_set_def_opts)
export(div_f)
export(finalizeHtml)
export(gdo)
export(guidesChr)
export(guidesDeparse)
export(guidesFile)
export(guidesPrint)
export(guidesStr)
export(has_Rdiff)
export(make_blocking)
export(nchar_html)
export(pager_is_less)
export(ses)
export(span_f)
export(tag_f)
export(trimChr)
export(trimDeparse)
export(trimFile)
export(trimPrint)
export(trimStr)
export(view_or_browse)
exportClasses(AlignThreshold)
exportClasses(Diff)
exportClasses(PagerOff)
exportClasses(PagerSystem)
exportClasses(PagerSystemLess)
exportClasses(PaletteOfStyles)
exportClasses(Style)
exportClasses(StyleAnsi)
exportClasses(StyleAnsi256DarkRgb)
exportClasses(StyleAnsi256DarkYb)
exportClasses(StyleAnsi256LightRgb)
exportClasses(StyleAnsi256LightYb)
exportClasses(StyleAnsi8NeutralRgb)
exportClasses(StyleAnsi8NeutralYb)
exportClasses(StyleFuns)
exportClasses(StyleHtml)
exportClasses(StyleHtmlLightRgb)
exportClasses(StyleHtmlLightYb)
exportClasses(StyleRaw)
exportClasses(StyleSummary)
exportClasses(StyleSummaryHtml)
exportClasses(StyleText)
exportMethods("[")
exportMethods(diffObj)
exportMethods(head)
exportMethods(summary)
exportMethods(tail)
import(crayon)
import(methods)
importFrom(grDevices,rgb)
importFrom(stats,ave)
importFrom(stats,frequency)
importFrom(stats,is.ts)
importFrom(stats,setNames)
importFrom(tools,Rdiff)
importFrom(utils,browseURL)
importFrom(utils,capture.output)
importFrom(utils,file_test)
importFrom(utils,packageVersion)
importFrom(utils,read.csv)
useDynLib(diffobj, .registration=TRUE, .fixes="DIFFOBJ_")
# diffobj
## v0.2.2
* Set `RNGversion()` due to changes to sampling mechanism.
## v0.2.0-1
### Features
* [#129](https://github.com/brodieG/diffobj/issues/129): Allow pager
specification via lists rather than full `Pager` objects for easier changes to
defaults. As part of this we changed `StyleRaw` objects to use default
pager instead of `PagerOff`.
* [#126](https://github.com/brodieG/diffobj/issues/126): Add embedding diffs in
Shiny to vignette.
* [#119](https://github.com/brodieG/diffobj/issues/119): `ignore.whitespace` now
also ignores white space differences adjoining punctuation.
* [#118](https://github.com/brodieG/diffobj/issues/118): New option to preserve
temporary diff file output when using pager (see `?Pager`).
* [#114](https://github.com/brodieG/diffobj/issues/114): New options `strip.sgr`
and `sgr.supported` allow finer control of what happens when input already
contains ANSI CSI SGR and how ANSI CSI SGR is handled in string manipulations.
Related to this, `options(crayon.enabled=TRUE)` is no longer set when
capturing output prior to diff as it used to be. By default pre-existing ANSI
CSI SGR is stripped with a warning prior to comparison.
### Bugs
* [#131](https://github.com/brodieG/diffobj/issues/131): Fix missing slot in S4
class definition (discovered by Bill Dunlap).
* [#127](https://github.com/brodieG/diffobj/issues/127): Width CSS conflicts
with bootstrap (reported by @eckyu, debugged/fixed by @cpsievert).
## v0.1.11
* [#123](https://github.com/brodieG/diffobj/issues/123): Compatibility with R3.1
(@krlmlr).
* [#121](https://github.com/brodieG/diffobj/issues/121): Vignette describing how
to embed diffs in Rmd documents (@JBGruber).
* [#115](https://github.com/brodieG/diffobj/issues/115): Declare HTML page diff
encoding/charset as UTF-8 (@artemklevtsov).
## v0.1.10
* Comply with CRAN directive to remove references to packages not in
depends/imports/suggests in tests (these were run optionally before).
* Fix bugs in corner case handling when we hit `max.diffs`.
## v0.1.9
* Fix test failures caused by changes in tibble output
## v0.1.8
* [#111](https://github.com/brodieG/diffobj/issues/111): Fixed guides with
`row.names=FALSE` (thank you @[Henrik
Bengtsson](https://github.com/HenrikBengtsson)).
* [#113](https://github.com/brodieG/diffobj/issues/113): Adapt tests to new
`str` return values (thank you @[Martin
Mächler](https://github.com/mmaechler)).
## v0.1.7
* Fix tests for next `testthat` release.
* [#107](https://github.com/brodieG/diffobj/issues/107): Diffs on quoted
language
* [#108](https://github.com/brodieG/diffobj/issues/108): Problems caused by
copying `crayon` functions
([@seulki-choi](https://stackoverflow.com/users/7788015/seulki-choi),
@gaborcsardi)
* [#100](https://github.com/brodieG/diffobj/issues/100): R_useDynamicSymbols
* [#97](https://github.com/brodieG/diffobj/issues/97): 2D Guidelines fixes for
data.table, tibble
* [#96](https://github.com/brodieG/diffobj/issues/96): Warnings when comparing
large data tables.
* [#94](https://github.com/brodieG/diffobj/issues/94): Guide detection problems
in nested lists.
* [#105](https://github.com/brodieG/diffobj/issues/105): Copyright tweaks.
## v0.1.6
* [#87](https://github.com/brodieG/diffobj/issues/87): `diffobj` is now GPL (>=2)
instead of GPL-3.
* [#81](https://github.com/brodieG/diffobj/issues/81): Better handling of mixed
UTF-8 / ASCII strings, reported by [jennybc](https://github.com/jennybc)
* [#88](https://github.com/brodieG/diffobj/issues/88): correctly handle trimming
when empty lists are involved, reported by [wch](https://github.com/wch)
* [#77](https://github.com/brodieG/diffobj/issues/77): `diffObj` now favors
dispatching to `diffPrint` unless `diffPrint` output is large
* [#82](https://github.com/brodieG/diffobj/issues/82): `diffChr` and `ses` now
treat `NA` as "NA" (needed with change in `nchar(NA)` in base R)
* [#85](https://github.com/brodieG/diffobj/issues/85): Improved alignment of
unwrapped atomic vector diffs
* [#83](https://github.com/brodieG/diffobj/issues/83): Improve pager auto
detection (note now ANSI output is only allowed by default if terminal
supports ANSI colors and the system pager is `less`, see `?Pager` for details)
* [#92](https://github.com/brodieG/diffobj/issues/92),
[#80](https://github.com/brodieG/diffobj/issues/80),
[#45](https://github.com/brodieG/diffobj/issues/45): basic implementation of
S4 guidelines and trimming (full resolution eventually with
[#33](https://github.com/brodieG/diffobj/issues/33))
* [#84](https://github.com/brodieG/diffobj/issues/84): simplify how to call
`diffChr` for improved performance, including "optimization" of
`convert.hz.whitespace`.
* [#64](https://github.com/brodieG/diffobj/issues/64): fix line limit in corner
case
* More robust handling of external `diff*` methods and of how `diffObj` calls
`diffStr` and `diffPrint`
## v0.1.5
* [#71](https://github.com/brodieG/diffobj/issues/71): Buggy diffs b/w data
frames when one has sequential row numbers and the other does not, loosely
related to [#38](https://github.com/brodieG/diffobj/issues/38)
* [#69](https://github.com/brodieG/diffobj/issues/69): Improve performance on
outputs with large print/show output, and other assorted minor optimizations
* [#72](https://github.com/brodieG/diffobj/issues/72): Warn when `style`
parameter overrides other user supplied parameters
* [#70](https://github.com/brodieG/diffobj/issues/70): Improve word contrast in YB
HTML mode
* [#63](https://github.com/brodieG/diffobj/issues/63): Show `all.equal` output
when objects are not `all.equal` but there are no visible differences
* Add [Mean Relative
Indifference](http://htmlpreview.github.io/?https://raw.githubusercontent.com/brodieG/diffobj/master/inst/doc/metacomp.html)
vignette and update vignette styling
## v0.1.4
* [#67](https://github.com/brodieG/diffobj/issues/67): Fix CRAN Binaries
* Clarified that C code is heavily modified and incompatible with original
`libmba` implementation
## v0.1.3
* First version on CRAN
* [#51](https://github.com/brodieG/diffobj/issues/51): use RStudio viewport to display HTML diffs when running in RStudio, as per [Noam Ross](https://twitter.com/noamross/status/760115813559009280)
* [#54](https://github.com/brodieG/diffobj/issues/54): [#55](https://github.com/brodieG/diffobj/issues/55), scale HTML output to viewport width (see `?Style`)
* [#53](https://github.com/brodieG/diffobj/issues/53): default term colors computed on run instead of on package load
* [#56](https://github.com/brodieG/diffobj/issues/56): disable wrap for HTML output
* HTML output now captured with default width 80 since there is no explicit relationship between HTML viewport width and `getOption("width")`
* The `style` parameter now accepts lists to use as instantiation arguments for `Style` objects (see `?Style`)
* Fix subtle rendering and formatting application flaws
* Switch Travis shields to SVG per Gábor Csárdi
* Improve in-hunk alignment of partially matching lines
* Compile with `-pedantic`, fix related warnings [Arun](http://stackoverflow.com/users/559784/arun)
* Improved coverage and more robust testing
* Several internal structure changes to accommodate improvements
## v0.1.2
* [#46](https://github.com/brodieG/diffobj/issues/46): Guide and Trim Problems with Lists
* [#47](https://github.com/brodieG/diffobj/issues/47): Output Format in non-ANSI Terminals Without Browser (reported by [Frank](https://github.com/brodieG/diffobj/issues/47))
* [#48](https://github.com/brodieG/diffobj/issues/48): `make_blocking` Default prompt Confusing (reported by [Frank](https://github.com/brodieG/diffobj/issues/47))
* [#49](https://github.com/brodieG/diffobj/issues/49): In-Hunk Word Diffs Issues when Unwrap-diffing Atomics
* [#50](https://github.com/brodieG/diffobj/issues/50): CSS Lost in Rstudio Server Sessions (reported by [Steven Beaupré](https://chat.stackoverflow.com/users/4064778/steven-beaupre))
## v0.1.1
* Turn off unwrapping for _named_ atomic vectors (see [#43](https://github.com/brodieG/diffobj/issues/43))
* [#44](https://github.com/brodieG/diffobj/issues/44): Proper handling of NULL objects in `diffStr`
* [#41](https://github.com/brodieG/diffobj/issues/41): Compilation Issues in Winbuilder
## v0.1.0
* Initial Release
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
# Copyright (C) 2019 Brodie Gaslam
#
# This file is part of "diffobj - Diffs for R Objects"
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# Go to <https://www.r-project.org/Licenses/GPL-2> for a copy of the license.
#' @include s4.R
NULL
#' Finalizing Methods for HTML Output
#'
#' Used as the \code{finalizer} slot to \code{\link{StyleHtml}} objects to wrap
#' character output prior to output to device. Used primarily by styles that
#' output to HTML to properly configure HTML page structure, including injecting
#' JS, CSS, etc..
#'
#' @param x object to finalize
#' @param x.chr character text representation of \code{x}, typically generated
#' with the \code{as.character} method for \code{x}
#' @param js character javascript code to append to HTML representation
#' @param ... arguments to pass on to methods
#' @export
setGeneric(
"finalizeHtml", function(x, ...) standardGeneric("finalizeHtml") # nocov
)
#' @rdname finalizeHtml
setMethod("finalizeHtml", c("ANY"),
function(x, x.chr, js, ...) {
if(!is.character(x.chr)) stop("Argument `x.chr` must be character")
if(!is.chr.1L(js)) stop("Argument `js` must be character(1L) and not NA.")
style <- x@etc@style
html.output <- style@html.output
pager <- style@pager
if(html.output == "auto") {
html.output <- if(is(pager, "PagerBrowser")) "page" else "diff.only"
}
if(html.output %in% c("diff.w.style", "page")) {
css.txt <- try(paste0(readLines(style@css), collapse="\n"), silent=TRUE)
if(inherits(css.txt, "try-error")) {
cond <- attr(css.txt, "condition")
warning(
"Unable to read provided css file \"", style@css, "\" (error: ",
paste0(conditionMessage(cond), collapse=""), ")."
)
css <- ""
} else {
css <- sprintf("<style type='text/css'>\n%s\n</style>", css.txt)
}
}
if(html.output == "diff.w.style") {
tpl <- "%s%s"
} else if (html.output == "page") {
x.chr <- enc2utf8(x.chr)
charset <-
'<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>'
tpl <- sprintf("
<!DOCTYPE html>
<html>
<head>
%s\n
%%s\n
</head>
<body>
<div id='diffobj_outer'>\n%%s\n</div>
<script type='text/javascript'>\n%s\n</script>
</body>
</html>",
charset,
js
)
} else if (html.output == "diff.only") {
css <- ""
tpl <- "%s%s"
} else
stop("Internal Error: unexpected html.output; contact maintainer.")# nocov
sprintf(tpl, css, paste0(x.chr, collapse=""))
}
)
# Copyright (C) 2019 Brodie Gaslam
#
# This file is part of "diffobj - Diffs for R Objects"
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# Go to <https://www.r-project.org/Licenses/GPL-2> for a copy of the license.
# Retrieves data from the data elements of the Diff object based on the index
# values provided in ind. Positive values draw from `tar` elements, and
# negative draw from `cur` elements.
#
# returns a list with the elements. If type is length 1, you will probably
# want to unlist the return value
get_dat <- function(x, ind, type) {
stopifnot(
is(x, "Diff"), is.integer(ind),
is.chr.1L(type) && type %in% .diff.dat.cols
)
# Need to figure out what zero indices are; previously would return
# NA_character_, but now since we're getting a whole bunch of different
# stuff not sure what the right return value should be, or even if we produce
# zero indices anymore
get_dat_raw(ind, x@tar.dat[[type]], x@cur.dat[[type]])
}
get_dat_raw <- function(ind, tar, cur) {
template <- tar[0L]
length(template) <- length(ind)
template[which(ind < 0L)] <- cur[abs(ind[ind < 0L])]
template[which(ind > 0L)] <- tar[abs(ind[ind > 0L])]
template
}
This diff is collapsed.
# Copyright (C) 2019 Brodie Gaslam
#
# This file is part of "diffobj - Diffs for R Objects"
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# Go to <https://www.r-project.org/Licenses/GPL-2> for a copy of the license.
#' @include misc.R
NULL
#' Make Functions That Wrap Text in HTML Tags
#'
#' Helper functions to generate functions to use as slots for the
#' \code{StyleHtml@funs} classes. These are functions that return
#' \emph{functions}.
#'
#' \code{tag_f} and related functions (\code{div_f}, \code{span_f}) produce
#' functions that are vectorized and will apply opening and closing tags to
#' each element of a character vector. \code{container_f} on the other hand
#' produces a function will collapse a character vector into length 1, and only
#' then applies the tags. Additionally, \code{container_f} already comes with
#' the \dQuote{diffobj-container} class specified.
#'
#' @note inputs are assumed to be valid class names or CSS styles.
#'
#' @export
#' @param tag character(1L) a name of an HTML tag
#' @param class character the CSS class(es)
#' @param style named character inline styles, where the name is the CSS
#' property and the value the value.
#' @return a function that accepts a character parameter. If applied, each
#' element in the character vector will be wrapped in the div tags
#' @aliases div_f, span_f, cont_f
#' @examples
#' ## Assuming class 'ex1' has CSS styles defined elsewhere
#' tag_f("div", "ex1")(LETTERS[1:5])
#' ## Use convenience function, and add some inline styles
#' div_f("ex2", c(color="green", `font-family`="arial"))(LETTERS[1:5])
#' ## Notice how this is a div with pre-specifed class,
#' ## and only one div is created around the entire data
#' cont_f()(LETTERS[1:5])
tag_f <- function(tag, class=character(), style=character()) {
stopifnot(is.chr.1L(tag), is.character(class), is.character(style))
function(x) {
if(!is.character(x)) stop("Argument `x` must be character.")
if(!length(x)) character(0L) else
paste0(
"<", tag,
if(length(class)) paste0(" class='", paste0(class, collapse=" "), "'"),
if(length(style))
paste0(
" style='",
paste(names(style), style, sep=": ", collapse="; "), ";'"
),
">", x, "</", tag, ">"
)
} }
#' @export
#' @rdname tag_f
div_f <- function(class=character(), style=character())
tag_f("div", class, style)
#' @export
#' @rdname tag_f
span_f <- function(class=character(), style=character())
tag_f("span", class, style)
#' @export
#' @rdname tag_f
cont_f <- function(class=character()) {
stopifnot(is.character(class))
function(x) {
if(!is.character(x)) stop("Argument `x` must be character.")
sprintf(
paste0(
"<div class='diffobj-container%s'><pre class='diffobj-content'>",
"%s</pre></div>"
),
if(length(class)) paste0(" ", class, collapse="") else "",
paste0(x, collapse="")
)
} }
#' Count Text Characters in HTML
#'
#' Very simple implementation that will fail if there are any \dQuote{>} in the
#' HTML that are not closing tags, and assumes that HTML entities are all one
#' character wide. Also, spaces are counted as one width each because the
#' HTML output is intended to be displayed inside \code{<PRE>} tags.
#'
#' @export
#' @param x character
#' @param ... unused for compatibility with internal use
#' @return integer(length(x)) with number of characters of each element
#' @examples
#' nchar_html("<a href='http:www.domain.com'>hello</a>")
nchar_html <- function(x, ...) {
stopifnot(is.character(x) && !anyNA(x))
tag.less <- gsub("<[^>]*>", "", x)
# Thanks ridgerunner for html entity removal regex
# http://stackoverflow.com/users/433790/ridgerunner
# http://stackoverflow.com/a/8806462/2725969
ent.less <-
gsub("&(?:[a-z\\d]+|#\\d+|#x[a-f\\d]+);", "X", tag.less, perl=TRUE)
nchar(ent.less)
}
This diff is collapsed.
# Copyright (C) 2019 Brodie Gaslam
#
# This file is part of "diffobj - Diffs for R Objects"
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# Go to <https://www.r-project.org/Licenses/GPL-2> for a copy of the license.
# Compute all the different gutter components and report max width
gutter_dat <- function(etc) {
stopifnot(is(etc, "Settings"))
old.opt <- options(crayon.enabled=TRUE)
on.exit(options(old.opt))
funs <- etc@style@funs
text <- etc@style@text
# get every slot except the pad slot; we'll then augment them so they have
# all the same number of characters if the style class inherits from
# Raw, which should be the case for raw, ansi8 and ansi255. Finally apply
# functions; note we assume the provided gutter characters don't contain
# ANSI escapes. We're a bit sloppy here with how we pull the relevant stuff
slot.nm <- slotNames(text)
slots <- slot.nm[grepl("^gutter\\.", slot.nm) & slot.nm != "gutter.pad"]
gutt.txt <- vapply(slots, slot, character(1L), object=text)
gutt.dat <- if(is(etc@style, "Raw")) format(gutt.txt) else gutt.txt
gutt.format.try <- try({
gutt.dat.format <- vapply(
slots,
function(x) slot(funs, sprintf("%s", x))(gutt.dat[x]),
character(1L)