Last active
August 29, 2015 14:15
-
-
Save cpsievert/211357490a854b814613 to your computer and use it in GitHub Desktop.
Compare output of plotly::gg2list() in two different versions of plotly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
json_diff <- function(x, old_ref = "master", new_ref) { | |
if (!nchar(Sys.which("json-diff"))) | |
stop("The npm module json-diff is required to see json diffs") | |
devtools::install_github("ropensci/plotly", ref = old_ref) | |
old_json <- paste0(old_ref, ".json") | |
cat_json(x, old_json) | |
if (missing(new_ref)) { | |
if (basename(getwd()) != "plotly") | |
stop("Either set working directory to plotly's R package source or give a GitHub reference to install") | |
devtools::load_all() | |
new_ref <- "local" | |
} else { | |
devtools::install_github("ropensci/plotly", ref = new_ref) | |
} | |
new_json <- paste0(new_ref, ".json") | |
cat_json(x, new_json) | |
system(paste("json-diff", old_json, new_json)) | |
} | |
cat_json <- function(y, nm) { | |
json <- RJSONIO::toJSON(plotly::gg2list(y), pretty = TRUE) | |
cat(json, file = nm) | |
} | |
library("plotly") | |
no_panels <- ggplot(mtcars, aes(mpg, wt)) + geom_point() | |
free_both <- no_panels + facet_wrap(~am+vs, scales = "free") | |
# compare master branch on GitHub to local source | |
json_diff(free_both) | |
# compare master branch on GitHub to 'carson-scales-free' branch | |
# json_diff(free_both, new_ref = "carson-scales-free") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment