Skip to content
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
Merged

Function as data #1527

merged 14 commits into from Feb 1, 2016

Conversation

@thomasp85
Copy link
Member

@thomasp85 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?)
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

} 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
Copy link
Member

@hadley 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
Copy link
Member Author

@thomasp85 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
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@hadley
Copy link
Member

@hadley 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
Copy link
Member Author

@thomasp85 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
Copy link
Member Author

@thomasp85 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
Copy link
Member

@hadley hadley commented Feb 1, 2016

Just a point for the future. I fixed locally

@lock
Copy link

@lock lock bot commented Jan 18, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants