New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function as data #1527

Merged
merged 14 commits into from Feb 1, 2016

Conversation

Projects
None yet
2 participants
@thomasp85
Member

thomasp85 commented Jan 28, 2016

This is a follow up on PR #1486

Summary of changes:

  • Add fortify.function that returns function unchanged
  • Add layer_data method to Layer base class that takes the plot data as input and returns the data associated with the layer
  • Remove the need for waiver-check in map_layout
  • Add unit tests for layer_data method

Possible additions:

  • Documentation of function-as-data functionality somewhere (don't really know the best location for this - any idea?)
R/layer.r Outdated
stop("Data function must return a data.frame")
}
return(data)
}

This comment has been minimized.

@hadley

hadley Jan 31, 2016

Member

I think this would be better with no returns and a final else block

R/layer.r Outdated
} else if (is.function(self$data)) {
data <- self$data(plot_data)
if (!is.data.frame(data)) {
stop("Data function must return a data.frame")

This comment has been minimized.

@hadley

hadley Jan 31, 2016

Member

This needs call. = FALSE

l <- geom_point(data = head)
expect_equal(l$layer_data(mtcars), head(mtcars))
l <- geom_point(data = nrow)
expect_error(l$layer_data(mtcars))

This comment has been minimized.

@hadley

hadley Jan 31, 2016

Member

Can you please check for the specific error message?

@hadley

This comment has been minimized.

Member

hadley commented Jan 31, 2016

This is looking good. A few points:

  • Can you please add a bullet point to NEWS?
  • Probably best to document this in layer()

@hadley hadley modified the milestone: v2.1.0 Jan 31, 2016

@thomasp85

This comment has been minimized.

Member

thomasp85 commented Feb 1, 2016

All points have been addressed...

@@ -101,6 +128,20 @@ Layer <- ggproto("Layer", NULL,
cat(snakeize(class(self$position)[[1]]), "\n")
},
layer_data = function(self, plot_data) {
if (is.waive(self$data)) {
data <- plot_data

This comment has been minimized.

@hadley

hadley Feb 1, 2016

Member

You can drop the data <- in all the alternatives

hadley added a commit that referenced this pull request Feb 1, 2016

@hadley hadley merged commit 0cd0bac into tidyverse:master Feb 1, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@hadley

This comment has been minimized.

Member

hadley commented Feb 1, 2016

One other idea now that I've merged it - what if the fortify happened in layer_data() as well?

@thomasp85

This comment has been minimized.

Member

thomasp85 commented Feb 1, 2016

Possible error because of unknown data type will first happen when plotting - don't know if that is desirable?

@thomasp85

This comment has been minimized.

Member

thomasp85 commented Feb 1, 2016

Should I redo the layer_data or is it merged and accepted and it was just a point for the future?

@hadley

This comment has been minimized.

Member

hadley commented Feb 1, 2016

Just a point for the future. I fixed locally

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment