Skip to content

Commit b038e8f

Browse files
committed
implement $.element for backward compatibility
1 parent df02b37 commit b038e8f

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

NAMESPACE

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# Generated by roxygen2: do not edit by hand
22

3-
S3method("$",ggproto)
4-
S3method("$",ggproto_parent)
5-
S3method("$",theme)
63
S3method("$<-",uneval)
74
S3method("+",gg)
85
S3method("[",mapped_discrete)
@@ -16,6 +13,9 @@ S3method(as.data.frame,mapped_discrete)
1613
S3method(as.list,ggproto)
1714
S3method(autolayer,default)
1815
S3method(autoplot,default)
16+
S3method(base::`$`, ggproto)
17+
S3method(base::`$`, ggproto_parent)
18+
S3method(base::`$`, theme)
1919
S3method(c,mapped_discrete)
2020
S3method(drawDetails,zeroGrob)
2121
S3method(format,ggproto)

R/ggproto.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ fetch_ggproto <- function(x, name) {
152152

153153
}
154154

155-
#' @export
155+
# Prevents bug described in S7/#390
156+
#' @rawNamespace S3method(base::`$`, ggproto)
156157
`$.ggproto` <- function(x, name) {
157158
res <- fetch_ggproto(x, name)
158159
if (!is.function(res)) {
@@ -162,7 +163,7 @@ fetch_ggproto <- function(x, name) {
162163
make_proto_method(x, res, name)
163164
}
164165

165-
#' @export
166+
#' @rawNamespace S3method(base::`$`, ggproto_parent)
166167
`$.ggproto_parent` <- function(x, name) {
167168
res <- fetch_ggproto(.subset2(x, "parent"), name)
168169
if (!is.function(res)) {

R/theme-elements.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ NULL
8383
#' @rdname element
8484
element <- S7::new_class("element", abstract = TRUE)
8585

86+
S7::method(`$`, element) <-
87+
function(x, i) {
88+
if (!S7::prop_exists(x, i)) {
89+
return(NULL)
90+
}
91+
S7::prop(x, i)
92+
}
93+
8694
#' @export
8795
#' @rdname element
8896
element_blank <- S7::new_class("element_blank", parent = element)

R/theme.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,8 @@ combine_elements <- function(e1, e2) {
942942
e1
943943
}
944944

945-
#' @export
945+
# Prevents bug described in S7/#390
946+
#' @rawNamespace S3method(base::`$`, theme)
946947
`$.theme` <- function(x, ...) {
947948
.subset2(x, ...)
948949
}

0 commit comments

Comments
 (0)