Skip to content

For data, NULL != data.frame() #31

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

Closed
hadley opened this issue Dec 3, 2009 · 2 comments · Fixed by #499
Closed

For data, NULL != data.frame() #31

hadley opened this issue Dec 3, 2009 · 2 comments · Fixed by #499
Labels
bug an unexpected problem or unintended behavior
Milestone

Comments

@hadley
Copy link
Member

hadley commented Dec 3, 2009

For example,

qplot(mpg, wt, data = mtcars) + 
  geom_point(data = data.frame(), colour = "red")

should display black points.

This can occur when subsetting and is annoying.

@wch
Copy link
Member

wch commented Apr 16, 2012

The map_layout() function in panel.r assumes that if it gets an empty data frame, then the data should be inherited from plot_data. The problem is that there's no way to tell whether the empty data frame is passed in, or if it was just not specified in the layer. When the geom is not specified, this is what happens: layer$new calls fortify.NULL(), which returns data.frame(), and it's this data frame that can't be distinguished from an empty data frame passed in to the layer.

One possible solution is to make fortify.NULL() add an attribute to the data frame, and then test for that attribute in map_layout().

@wch
Copy link
Member

wch commented Apr 16, 2012

The fix I've submitted works for this, although you need to set inherit.aes = FALSE:

qplot(mpg, wt, data = mtcars) + geom_point(data = data.frame(), colour = "red", inherit.aes = FALSE)

@hadley hadley closed this as completed in fe42a64 Apr 20, 2012
@lock lock bot locked as resolved and limited conversation to collaborators Jun 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants