hadley/ggplot2 — pull request #642 by wch (2012-08-07 17:35:18+00:00)
Title: Change proto() to gg(proto()). Fixes #583

This fixes #583. It passes all tests, and visual tests are unchanged.

I'm not sure it should be merged though -- although it solves the printing problem, it'll break all code where people define their own geoms and stats in external packages.

There's also some weird behavior with printing that I don't understand. Depending on how you print it, it might or might not tell you that it's a `ggproto` object:

```R
str(z)
# proto object
# $ mapping : NULL
# $ geom_params:List of 1
# $ stat_params: Named list()
# $ stat :proto object
# ..parent: proto object
# .. .. parent: proto object
# $ inherit.aes: logi TRUE
# $ geom :proto object
# ..parent: proto object
# .. .. parent: proto object
# $ position :proto object
# ..parent: proto object
# .. .. parent: proto object
# .. .. .. parent: proto object
# $ subset : NULL
# $ data : list()
# ..- attr(*, "class")= chr "waiver"
# $ show_guide : logi NA
# parent: proto object

z
# geom_point: na.rm = FALSE
# stat_identity:
#
# attr(,"class")
# [1] "proto" "environment"

class(z)
# [1] "ggproto" "proto" "environment"
```

There's another bizarre property of proto objects. If you set the class via `structure()`, even if you _don't_ assign it back to the variable, it modifies the class of the object.

```R
class(z)
# [1] "ggproto" "proto" "environment"

structure(z, class = c("foo", class(z)))
# geom_point: na.rm = FALSE
# stat_identity:
#
# attr(,"class")
# [1] "proto" "environment"

class(z)
# [1] "foo" "ggproto" "proto" "environment"
```

I'm concerned that, because proto is so opaque and confusing, there may be unintended consequences of this change.