ggplot2 icon indicating copy to clipboard operation
ggplot2 copied to clipboard

Feature request: nicer error message for coord_cartesian

Open petyaracz opened this issue 3 years ago • 1 comments

I would like coord_cartesian to return a more human-readable error when I mess up the syntax:

example

library(ggplot2)

ggplot(iris, aes(Petal.Length,Petal.Width)) + 
  geom_point() +
  coord_cartesian(xlim(2,6))

observed behaviour

Error in rep(no, length.out = len) : 
  attempt to replicate an object of type 'environment'
In addition: Warning message:
In is.na(coord_limits) :
  is.na() applied to non-(list or vector) of type 'environment'

expected behaviour

Error in coord_cartesian: did you mean "xlim = c()"?

petyaracz avatar Sep 02 '21 13:09 petyaracz

Reprex:

library(ggplot2)

ggplot(iris, aes(Petal.Length,Petal.Width)) + 
  geom_point() +
  coord_cartesian(xlim(2,6))
#> Warning in is.na(coord_limits): is.na() applied to non-(list or vector) of type
#> 'environment'
#> Error in rep(no, length.out = len): attempt to replicate an object of type 'environment'

Created on 2022-04-19 by the reprex package (v2.0.1)

Just needs a little type checking in coord_cartesian().

hadley avatar Apr 19 '22 13:04 hadley

Considered completed by #4894.

teunbrand avatar Jul 04 '23 17:07 teunbrand