Skip to content

make list() behave as NULL #2315

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
aphalo opened this issue Oct 30, 2017 · 1 comment
Closed

make list() behave as NULL #2315

aphalo opened this issue Oct 30, 2017 · 1 comment

Comments

@aphalo
Copy link
Contributor

aphalo commented Oct 30, 2017

To me it feels counter intuitive that NULL is a no-op while list() results in a modified object. Of course the rendered plots do not differ. In the current definition of function add_ggplot() the test for returning p unchanged uses is.null(object), one could use length(object) == 0 instead, but maybe it is just me that is surprised, and there is a good reason behind treating NULL and list() differently.

library(ggplot2)

myplot <- ggplot(data = mtcars,
                 aes(x=disp, y=mpg)) +
  geom_point()

identical(myplot, myplot + NULL)
#> [1] TRUE
identical(myplot, myplot + list())
#> [1] FALSE
@hadley
Copy link
Member

hadley commented Oct 30, 2017

Post #2309 it's consistent (the plot is always cloned so identical() is never TRUE).

@hadley hadley closed this as completed Oct 30, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants