Skip to content

Commit

Permalink
BUGFIX: prevented supplementary data from being dropped when using + …
Browse files Browse the repository at this point in the history
…or - methods
  • Loading branch information
jonocarroll committed Aug 19, 2016
1 parent d5439ce commit 8667a60
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ggghost
Title: Capture the Spirit of Your 'ggplot2' Calls
Version: 0.2.0
Version: 0.2.1
Authors@R: person("Jonathan", "Carroll", email = "[email protected]", role = c("aut", "cre"))
Maintainer: Jonathan Carroll <[email protected]>
Description: Creates a reproducible 'ggplot2' object by storing the data and calls.
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# CHANGES in ggghost 0.2.1
==========

* Corrected a minor bug which dropped supplementary data when using `+` or `-`.

# CHANGES in ggghost 0.2.0
==========

Expand Down
15 changes: 12 additions & 3 deletions R/ghost.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ is.ggghost <- function(x) inherits(x, "ggghost")
if (is.ggghost(e1)) {
new_obj <- structure(append(e1, match.call()[[3]]), class = c("ggghost", "gg"))
attr(new_obj, "data") <- attr(e1, "data")
if (!is.null(attr(e1, "suppdata"))) {
attr(new_obj, "suppdata") <- attr(e1, "suppdata")
}
return(new_obj)
} else {
return(e1 %+% e2)
Expand Down Expand Up @@ -156,6 +159,9 @@ is.ggghost <- function(x) inherits(x, "ggghost")
}
new_obj <- structure(unclass(e1)[-grep(sub("\\(.*$", "", call_to_remove)[1], unclass(e1))], class = c("ggghost", "gg"))
attr(new_obj, "data") <- attr(e1, "data")
if (!is.null(attr(e1, "suppdata"))) {
attr(new_obj, "suppdata") <- attr(e1, "suppdata")
}
return(new_obj)
}
}
Expand All @@ -169,7 +175,7 @@ is.ggghost <- function(x) inherits(x, "ggghost")
#' @return The ggplot plot data (invisibly). Used for the side-effect of producing a ggplot plot.
#' @export
print.ggghost <- function(x, ...) {
recover_data(x)
recover_data(x, supp = TRUE)
plotdata <- eval(parse(text = paste(x, collapse = " + ")))
print(plotdata)
return(invisible(plotdata))
Expand Down Expand Up @@ -248,6 +254,9 @@ summary.ggghost <- function(object, ...) {
subset.ggghost <- function(x, ...) {
new_obj <- structure(unclass(x)[...], class = c("ggghost", "gg"))
attr(new_obj, "data") <- attr(x, "data")
if (!is.null(attr(x, "suppdata"))) {
attr(new_obj, "suppdata") <- attr(x, "suppdata")
}
return(new_obj)
}

Expand Down Expand Up @@ -283,7 +292,7 @@ reanimate <- function(object, gifname = "ggghost.gif", interval = 1, ani.width =
stopifnot(length(object) > 1)
animation::ani.options(interval = interval, ani.width = ani.width, ani.height = ani.height)
animation::saveGIF({
recover_data(object)
recover_data(object, supp = TRUE)
ggtmp <- object[[1]]
print(eval(ggtmp))
for (i in 2:length(object)) {
Expand Down Expand Up @@ -376,7 +385,7 @@ recover_data <- function(x, supp = TRUE) {
supp_data <- function(x) {

value <- attr(x, "suppdata")
if (length(value) == 0 & interactive()) warning("ggghostbuster: no supplementary data found", call. = FALSE)
# if (length(value) == 0 & interactive()) warning("ggghostbuster: no supplementary data found", call. = FALSE)

return(value)

Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ html_preview: false

[![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/ggghost)](https://cran.r-project.org/package=ggghost)
[![packageversion](https://img.shields.io/badge/Package%20version-0.1.9000-orange.svg?style=flat-square)](commits/master)
[![packageversion](https://img.shields.io/badge/Package%20version-0.2.1-orange.svg?style=flat-square)](commits/master)
[![Last-changedate](https://img.shields.io/badge/last%20change-`r gsub('-', '--', Sys.Date())`-yellowgreen.svg)](/commits/master)

[![Linux/Mac Travis Build Status](https://img.shields.io/travis/jonocarroll/ggghost/master.svg?label=Mac%20OSX%20%26%20Linux)](https://travis-ci.org/jonocarroll/ggghost)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active) [![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/ggghost)](https://cran.r-project.org/package=ggghost) [![packageversion](https://img.shields.io/badge/Package%20version-0.1.9000-orange.svg?style=flat-square)](commits/master) [![Last-changedate](https://img.shields.io/badge/last%20change-2016--08--18-yellowgreen.svg)](/commits/master)
[![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active) [![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/ggghost)](https://cran.r-project.org/package=ggghost) [![packageversion](https://img.shields.io/badge/Package%20version-0.2.1-orange.svg?style=flat-square)](commits/master) [![Last-changedate](https://img.shields.io/badge/last%20change-2016--08--18-yellowgreen.svg)](/commits/master)

[![Linux/Mac Travis Build Status](https://img.shields.io/travis/jonocarroll/ggghost/master.svg?label=Mac%20OSX%20%26%20Linux)](https://travis-ci.org/jonocarroll/ggghost) [![AppVeyor Build Status](https://img.shields.io/appveyor/ci/jonocarroll/ggghost/master.svg?label=Windows)](https://ci.appveyor.com/project/jonocarroll/ggghost) [![codecov](https://codecov.io/gh/jonocarroll/ggghost/branch/master/graph/badge.svg)](https://codecov.io/gh/jonocarroll/ggghost)

Expand Down
Binary file modified tests/testthat/Rplots.pdf
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/testthat/test_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,9 @@ recover_data(ggghostx, supp = TRUE)
test_that("supplementary data be successfully recovered",{
expect_identical(sdat_saved, sdat)
})

ggghostx <- ggghostx + geom_line()

test_that("supplementary data remains after adding a call", {
expect_identical(supp_data(ggghostx)[[2]], sdat)
})

0 comments on commit 8667a60

Please sign in to comment.