Code Monkey home page Code Monkey logo

diffviewer's Introduction

diffviewer

Codecov test coverage R-CMD-check

diffviewer provides an HTML widget for visually comparing files. It currently wraps three javascript libraries:

It extracts out common UI provided by shinytest and vdiffr.

Installation

You can install the released version of diffviewer from CRAN with:

install.packages("diffviewer")

Example

This is a basic example which shows you how to solve a common problem:

library(diffviewer)
path1 <- tempfile()
writeLines(letters, path1)
path2 <- tempfile()
writeLines(letters[-(10:11)], path2)

visual_diff(path1, path2)

diffviewer's People

Contributors

batpigandme avatar hadley avatar jbkunst avatar wch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

diffviewer's Issues

Repository has two copies of diffviewer.js

There is one in inst/htmlwidgets, and another in inst/htmlwidgets/lib/diffviewer. They are mostly the same, but not exactly, and I believe there should probably be just one copy of it.

diffviewer fails to show differences in some PNG files

With these two files, there are a few pixels that are different, but the visual diff does not color them in red.
However, magick::image_compare() does show the differences.

oldfile <- "file1.png"
newfile <- "file2.png"

library(magick)
old <- magick::image_read(oldfile)
new <- magick::image_read(newfile)

# Shows difference
image_compare(old, new)

# Does not show difference
library(diffviewer)
diffviewer::visual_diff(oldfile, newfile)

grided_default new
grided_default

This is the difference image generated by image_compare(). I've added arrows pointing to the pixels that are different.

diff

Here's the info about the pixels that are different:

old_data <- old[[1]]
new_data <- new[[1]]

idx <- old_data != new_data
which(idx, arr.ind = TRUE)
#>       dim1 dim2 dim3
#>  [1,]    1  512  185
#>  [2,]    2  512  185
#>  [3,]    3  512  185
#>  [4,]    1  512  196
#>  [5,]    2  512  196
#>  [6,]    3  512  196
#>  [7,]    1 1022  670
#>  [8,]    2 1022  670
#>  [9,]    3 1022  670
#> [10,]    1 1022  686
#> [11,]    2 1022  686
#> [12,]    3 1022  686
#> [13,]    1 1022 1136
#> [14,]    2 1022 1136
#> [15,]    3 1022 1136

old_data[idx]
#>  [1] 0f 82 fe 0e 81 fe e6 e6 e6 d7 d7 d7 e6 e6 e6

new_data[idx]
#>  [1] 00 7b ff 00 7b ff e7 e7 e7 d8 d8 d8 e7 e7 e7

cc @nstrayer

Cran Release

With the merge of #11 , would it be possible to update diffviewer alongside the next release of testthat?

I have already been bit by the bug in #11 when calling testthat::snapshot_review()

Should allow viewing files without diffs

This is something I've wanted for a while: to be able to just view a directory of files, without diffs. That would be useful for when the initial snapshots are created.

Should allow expanding context in diff

The text diff viewer currently only shows the changed portion with a few lines of context. It would be useful to be able to expand the context, similar to GitHub's diff viewer.

Release diffviewer 0.1.0

Prepare for release:

  • Check that description is informative
  • Check licensing of included files
  • Need alternative for csv2array (#7)
  • devtools::build_readme()
  • usethis::use_cran_comments()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • Update cran-comments.md
  • Review pkgdown reference index for, e.g., missing topics

Submit to CRAN:

  • usethis::use_version('minor')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted ๐ŸŽ‰
  • usethis::use_news_md()
  • usethis::use_github_release()
  • usethis::use_dev_version()
  • Update install instructions in README

Also compare dataframes?

It would be nice if diffviewer allowed to also compare dataframes.

For my own use, I created the small helper function below that creates tempfiles from the dataframes to be able to use diffviewer:

compare_DFs <- function(DF_new, DF_old) {
    
  OLD = tempfile(pattern = "OLD_", fileext = ".csv")
  NEW = tempfile(pattern = "NEW_", fileext = ".csv")
  
  readr::write_csv(DF_old, OLD)
  readr::write_csv(DF_new, NEW)
  
diffviewer::visual_diff(OLD, NEW)

}

SVGs generated by vdiffr are not displayed

With svglite this works:

file1 <- tempfile(fileext = ".svg")
file2 <- tempfile(fileext = ".svg")

svglite::svglite(file1); plot(1:3); dev.off()
svglite::svglite(file2); plot(2:4); dev.off()

diffviewer::visual_diff(file1, file2)

But SVGs generated by vdiffr are not displayed:

file3 <- tempfile(fileext = ".svg")
file4 <- tempfile(fileext = ".svg")

vdiffr::write_svg(function() plot(1:3), file3, "plot1")
vdiffr::write_svg(function() plot(2:4), file4, "plot2")

diffviewer::visual_diff(file3, file4)

I don't know if the SVGs generated by @thomasp85's version of the vdiffr engine work with diffviewer. Do you have this branch online Thomas?

Even if the new engine works, it would be nice for vdiffr users to be able to compare the old SVGs to the new ones when they transition to vdiffr 1.0. Or we just assume the SVGs to be equivalent?

Move `master` branch to `main`

The master branch of this repository will soon be renamed to main, as part of a coordinated change across several GitHub organizations (including, but not limited to: tidyverse, r-lib, tidymodels, and sol-eng). We anticipate this will happen by the end of September 2021.

That will be preceded by a release of the usethis package, which will gain some functionality around detecting and adapting to a renamed default branch. There will also be a blog post at the time of this master --> main change.

The purpose of this issue is to:

  • Help us firm up the list of targetted repositories
  • Make sure all maintainers are aware of what's coming
  • Give us an issue to close when the job is done
  • Give us a place to put advice for collaborators re: how to adapt

message id: euphoric_snowdog

Upkeep for diffviewer (2020)

2020

  • usethis::use_package_doc()
    Consider letting usethis manage your @importFrom directives here.
    usethis::use_import_from() is handy for this.
  • usethis::use_testthat(3) and upgrade to 3e, testthat 3e vignette
  • Align the names of R/ files and test/ files for workflow happiness.
    The docs for usethis::use_r() include a helpful script.
    usethis::rename_files() may be be useful.

2021

  • usethis::use_tidy_description()
  • usethis::use_tidy_dependencies()
  • usethis::use_tidy_github_actions() and update artisanal actions to use setup-r-dependencies
  • Remove check environments section from cran-comments.md
  • Bump required R version in DESCRIPTION to 3.6
  • Use lifecycle instead of artisanal deprecation messages, as described in Communicate lifecycle changes in your functions
  • Make sure RStudio appears in Authors@R of DESCRIPTION like so, if appropriate:
    person("RStudio", role = c("cph", "fnd"))

2022

2023

Necessary:

  • Update email addresses *@rstudio.com -> *@posit.co
  • Update copyright holder in DESCRIPTION: person(given = "Posit Software, PBC", role = c("cph", "fnd"))
  • Run devtools::document() to re-generate package-level help topic with DESCRIPTION changes
  • Double check license file uses '[package] authors' as copyright holder. Run use_mit_license()
  • Update logo (https://github.com/rstudio/hex-stickers); run use_tidy_logo()
  • usethis::use_tidy_coc()
  • usethis::use_tidy_github_actions()

Optional:

  • Review 2022 checklist to see if you completed the pkgdown updates
  • Prefer pak::pak("org/pkg") over devtools::install_github("org/pkg") in README
  • Consider running use_tidy_dependencies() and/or replace compat files with use_standalone()
  • use_standalone("r-lib/rlang", "types-check") instead of home grown argument checkers
  • Add alt-text to pictures, plots, etc; see https://posit.co/blog/knitr-fig-alt/ for examples

Created on 2023-10-30 with usethis::use_tidy_upkeep_issue(), using usethis v2.2.2.9000

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.