Skip to content

Commit eae4374

Browse files
committed
revert replacement functions
1 parent a7f9152 commit eae4374

File tree

4 files changed

+60
-39
lines changed

4 files changed

+60
-39
lines changed

NAMESPACE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@
22

33
S3method("$",ggproto)
44
S3method("$",ggproto_parent)
5+
S3method("$<-","ggplot2::element")
6+
S3method("$<-","ggplot2::gg")
7+
S3method("$<-","ggplot2::mapping")
58
S3method("[",mapped_discrete)
9+
S3method("[<-","ggplot2::element")
10+
S3method("[<-","ggplot2::gg")
11+
S3method("[<-","ggplot2::mapping")
612
S3method("[<-",mapped_discrete)
713
S3method("[[",ggproto)
14+
S3method("[[<-","ggplot2::element")
15+
S3method("[[<-","ggplot2::gg")
16+
S3method("[[<-","ggplot2::mapping")
817
S3method(.DollarNames,ggproto)
918
S3method(as.data.frame,mapped_discrete)
1019
S3method(as.list,ggproto)

R/aes.R

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,21 @@ local({
152152
S7::method(`[`, class_mapping) <- function(x, i, ...) {
153153
class_mapping(`[`(S7::S7_data(x), i, ...))
154154
}
155-
S7::method(`$<-`, class_mapping) <- S7::method(`[[<-`, class_mapping) <-
156-
function(x, i, value) {
157-
class_mapping(`[[<-`(S7::S7_data(x), i, value))
158-
}
159-
S7::method(`[<-`, class_mapping) <- function(x, i, value) {
160-
class_mapping(`[<-`(S7::S7_data(x), i, value))
161-
}
162155
})
163156

157+
#' @export
158+
`[[<-.ggplot2::mapping` <- function(x, i, value) {
159+
class_mapping(`[[<-`(S7::S7_data(x), i, value))
160+
}
161+
162+
#' @export
163+
`$<-.ggplot2::mapping` <- `[[<-.ggplot2::mapping`
164+
165+
#' @export
166+
`[<-.ggplot2::mapping` <- function(x, i, value) {
167+
class_mapping(`[<-`(S7::S7_data(x), i, value))
168+
}
169+
164170
#' Standardise aesthetic names
165171
#'
166172
#' This function standardises aesthetic names by converting `color` to `colour`

R/plot.R

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -248,22 +248,25 @@ local({
248248
}
249249
})
250250

251-
local({
252-
S7::method(`$<-`, class_gg) <- S7::method(`[[<-`, class_gg) <-
253-
function(x, i, value) {
254-
if (!S7::prop_exists(x, i) && S7::prop_exists(x, "meta")) {
255-
# See explanation in `$.ggplot2::gg`
256-
S7::prop(x, "meta")[[i]] <- value
257-
} else {
258-
S7::props(x) <- `[[<-`(S7::props(x), i, value)
259-
}
260-
x
261-
}
262-
S7::method(`[<-`, class_gg) <- function(x, i, value) {
263-
S7::props(x) <- `[<-`(S7::props(x), i, value)
264-
x
251+
#' @export
252+
`[<-.ggplot2::gg` <- function(x, i, value) {
253+
S7::props(x) <- `[<-`(S7::props(x), i, value)
254+
x
255+
}
256+
257+
#' @export
258+
`$<-.ggplot2::gg` <- function(x, i, value) {
259+
if (!S7::prop_exists(x, i) && S7::prop_exists(x, "meta")) {
260+
# See explanation in accessor
261+
S7::prop(x, "meta")[[i]] <- value
262+
} else {
263+
S7::props(x) <- `[[<-`(S7::props(x), i, value)
265264
}
266-
})
265+
x
266+
}
267+
268+
#' @export
269+
`[[<-.ggplot2::gg` <- `$<-.ggplot2::gg`
267270

268271
#' @importFrom S7 convert
269272
# S7 currently attaches the S3 method to the calling environment which gives `ggplot2:::as.list`

R/theme-elements.R

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -403,23 +403,26 @@ local({
403403
})
404404

405405
# Element setter methods
406-
local({
407-
S7::method(`$<-`, element) <- function(x, i, value) {
408-
# deprecate_soft0("4.1.0", I("`<ggplot2::element>$i <- value`"), I("`<ggplot2::element>@i <- value`"))
409-
S7::props(x) <- `[[<-`(S7::props(x), i, value)
410-
x
411-
}
412-
S7::method(`[<-`, element) <- function(x, i, value) {
413-
# deprecate_soft0("4.1.0", I("`<ggplot2::element>[i] <- value`"), I("`S7::props(<ggplot2::element>)[i] <- value`"))
414-
S7::props(x) <- `[<-`(S7::props(x), i, value)
415-
x
416-
}
417-
S7::method(`[[<-`, element) <- function(x, i, value) {
418-
# deprecate_soft0("4.1.0", I("`<ggplot2::element>[[i]] <- value`"), I("S7::prop(<ggplot2::element>, i) <- value"))
419-
S7::props(x) <- `[[<-`(S7::props(x), i, value)
420-
x
421-
}
422-
})
406+
#' @export
407+
`$<-.ggplot2::element` <- function(x, i, value) {
408+
# deprecate_soft0("4.1.0", I("`<ggplot2::element>$i <- value`"), I("`<ggplot2::element>@i <- value`"))
409+
S7::props(x) <- `[[<-`(S7::props(x), i, value)
410+
x
411+
}
412+
413+
#' @export
414+
`[<-.ggplot2::element` <- function(x, i, value) {
415+
# deprecate_soft0("4.1.0", I("`<ggplot2::element>[i] <- value`"), I("`S7::props(<ggplot2::element>)[i] <- value`"))
416+
S7::props(x) <- `[<-`(S7::props(x), i, value)
417+
x
418+
}
419+
420+
#' @export
421+
`[[<-.ggplot2::element` <- function(x, i, value) {
422+
# deprecate_soft0("4.1.0", I("`<ggplot2::element>[[i]] <- value`"), I("S7::prop(<ggplot2::element>, i) <- value"))
423+
S7::props(x) <- `[[<-`(S7::props(x), i, value)
424+
x
425+
}
423426

424427
#' @export
425428
print.rel <- function(x, ...) print(noquote(paste(x, " *", sep = "")))

0 commit comments

Comments
 (0)