Skip to content

Commit 206c394

Browse files
committed
rename mapping to class_mapping
1 parent ef5db54 commit 206c394

File tree

11 files changed

+53
-24
lines changed

11 files changed

+53
-24
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ export(binned_scale)
292292
export(borders)
293293
export(calc_element)
294294
export(check_device)
295+
export(class_mapping)
295296
export(combine_vars)
296297
export(complete_theme)
297298
export(continuous_scale)

R/aes.R

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,20 @@ aes <- function(x, y, ...) {
105105
inject(aes(!!!args))
106106
})
107107

108-
mapping(rename_aes(args), env = parent.frame())
108+
class_mapping(rename_aes(args), env = parent.frame())
109109
}
110110

111-
mapping <- S7::new_class(
111+
#' The mapping class
112+
#'
113+
#' The mapping class holds a list of quoted expressions
114+
#' ([quosures][rlang::topic-quosure]) or constants. An object is typically
115+
#' constructed using the [`aes()`] function.
116+
#'
117+
#' @param x A list of quosures and constants.
118+
#' @param env An environment for symbols that are not quosures or constants.
119+
#'
120+
#' @export
121+
class_mapping <- S7::new_class(
112122
"mapping", parent = S7::new_S3_class("gg"),
113123
constructor = function(x, env = globalenv()) {
114124
check_object(x, is.list, "a {.cls list}")
@@ -119,7 +129,7 @@ mapping <- S7::new_class(
119129

120130
#' @export
121131
#' @rdname is_tests
122-
is.mapping <- function(x) S7::S7_inherits(x, mapping)
132+
is.mapping <- function(x) S7::S7_inherits(x, class_mapping)
123133

124134
# Wrap symbolic objects in quosures but pull out constants out of
125135
# quosures for backward-compatibility
@@ -157,21 +167,21 @@ new_aesthetic <- function(x, env = globalenv()) {
157167

158168
#' @export
159169
"[.ggplot2::mapping" <- function(x, i, ...) {
160-
mapping(NextMethod())
170+
class_mapping(NextMethod())
161171
}
162172

163173
# If necessary coerce replacements to quosures for compatibility
164174
#' @export
165175
"[[<-.ggplot2::mapping" <- function(x, i, value) {
166-
mapping(NextMethod())
176+
class_mapping(NextMethod())
167177
}
168178
#' @export
169179
"$<-.ggplot2::mapping" <- function(x, i, value) {
170-
mapping(NextMethod())
180+
class_mapping(NextMethod())
171181
}
172182
#' @export
173183
"[<-.ggplot2::mapping" <- function(x, i, value) {
174-
mapping(NextMethod())
184+
class_mapping(NextMethod())
175185
}
176186

177187
#' Standardise aesthetic names
@@ -212,7 +222,7 @@ substitute_aes <- function(x, fun = standardise_aes_symbols, ...) {
212222
x <- lapply(x, function(aesthetic) {
213223
as_quosure(fun(quo_get_expr(aesthetic), ...), env = environment(aesthetic))
214224
})
215-
mapping(x)
225+
class_mapping(x)
216226
}
217227
# x is a quoted expression from inside aes()
218228
standardise_aes_symbols <- function(x) {
@@ -310,7 +320,7 @@ aes_ <- function(x, y, ...) {
310320
}
311321
}
312322
mapping <- lapply(mapping, as_quosure_aes)
313-
mapping(rename_aes(mapping))
323+
class_mapping(rename_aes(mapping))
314324
}
315325

316326
#' @rdname aes_
@@ -336,7 +346,7 @@ aes_string <- function(x, y, ...) {
336346
new_aesthetic(x, env = caller_env)
337347
})
338348

339-
mapping(rename_aes(mapping))
349+
class_mapping(rename_aes(mapping))
340350
}
341351

342352
#' @export
@@ -357,7 +367,7 @@ aes_all <- function(vars) {
357367

358368
# Quosure the symbols in the empty environment because they can only
359369
# refer to the data mask
360-
mapping(lapply(vars, function(x) new_quosure(as.name(x), emptyenv())))
370+
class_mapping(lapply(vars, function(x) new_quosure(as.name(x), emptyenv())))
361371
}
362372

363373
#' Automatic aesthetic mapping
@@ -392,7 +402,7 @@ aes_auto <- function(data = NULL, ...) {
392402
aes <- c(aes, args[names(args) != "data"])
393403
}
394404

395-
mapping(rename_aes(aes))
405+
class_mapping(rename_aes(aes))
396406
}
397407

398408
mapped_aesthetics <- function(x) {

R/layer.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ validate_mapping <- function(mapping, call = caller_env()) {
213213
}
214214

215215
# For backward compatibility with pre-tidy-eval layers
216-
mapping(mapping)
216+
class_mapping(mapping)
217217
}
218218

219219
Layer <- ggproto("Layer", NULL,
@@ -265,7 +265,7 @@ Layer <- ggproto("Layer", NULL,
265265
setup_layer = function(self, data, plot) {
266266
# For annotation geoms, it is useful to be able to ignore the default aes
267267
if (isTRUE(self$inherit.aes)) {
268-
self$computed_mapping <- mapping(defaults(self$mapping, plot@mapping))
268+
self$computed_mapping <- class_mapping(defaults(self$mapping, plot@mapping))
269269

270270
# Inherit size as linewidth from global mapping
271271
if (self$geom$rename_size &&

R/plot-construction.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ S7::method(ggplot_add, list(class_guides, class_ggplot)) <-
156156
plot
157157
}
158158

159-
S7::method(ggplot_add, list(mapping, class_ggplot)) <-
159+
S7::method(ggplot_add, list(class_mapping, class_ggplot)) <-
160160
function(object, plot, ...) {
161-
S7::set_props(plot, mapping = mapping(defaults(object, plot@mapping)))
161+
S7::set_props(plot, mapping = class_mapping(defaults(object, plot@mapping)))
162162
}
163163

164164
S7::method(ggplot_add, list(theme, class_ggplot)) <-

R/plot.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class_ggplot <- S7::new_class(
88
layers = S7::class_list,
99
scales = class_scales_list,
1010
guides = class_guides,
11-
mapping = mapping,
11+
mapping = class_mapping,
1212
theme = theme,
1313
coordinates = class_coord,
1414
facet = class_facet,

R/quick-plot.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ qplot <- function(x, y, ..., data, facets = NULL, margins = FALSE,
7878
is_constant <- (!names(exprs) %in% ggplot_global$all_aesthetics) |
7979
vapply(exprs, quo_is_call, logical(1), name = "I")
8080

81-
mapping <- mapping(exprs[!is_missing & !is_constant], env = parent.frame())
81+
mapping <- class_mapping(exprs[!is_missing & !is_constant], env = parent.frame())
8282

8383
consts <- exprs[is_constant]
8484

man/class_mapping.Rd

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/_snaps/aes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
Don't know how to get alternative usage for `foo`.
5656

57-
# mapping() checks its inputs
57+
# class_mapping() checks its inputs
5858

5959
`x` must be a <list>, not an integer vector.
6060

tests/testthat/test-add.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
test_that("mapping class is preserved when adding mapping objects", {
22
p <- ggplot(mtcars) + aes(wt, mpg)
3-
expect_s7_class(p@mapping, mapping)
3+
expect_s7_class(p@mapping, class_mapping)
44
})

tests/testthat/test-aes.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ test_that("alternative_aes_extract_usage() can inspect the call", {
195195
expect_snapshot_error(alternative_aes_extract_usage(x))
196196
})
197197

198-
test_that("mapping() checks its inputs", {
199-
expect_snapshot_error(mapping(1:5))
198+
test_that("class_mapping() checks its inputs", {
199+
expect_snapshot_error(class_mapping(1:5))
200200
})
201201

202202
# Visual tests ------------------------------------------------------------

0 commit comments

Comments
 (0)