8
8
# ' [ggplot2()] and in individual layers.
9
9
# '
10
10
# ' This function also standardises aesthetic names by converting `color` to `colour`
11
- # ' (also in substrings, e.g. `point_color` to `point_colour`) and translating old style
12
- # ' R names to ggplot names (eg. `pch` to `shape`, `cex` to `size`).
11
+ # ' (also in substrings, e.g., `point_color` to `point_colour`) and translating old style
12
+ # ' R names to ggplot names (e.g., `pch` to `shape` and `cex` to `size`).
13
13
# '
14
14
# ' @section Quasiquotation:
15
15
# '
22
22
# ' programming vignette](http://dplyr.tidyverse.org/articles/programming.html)
23
23
# ' to learn more about these techniques.
24
24
# '
25
- # ' @param x,y,... List of name value pairs giving aesthetics to map to
26
- # ' variables. The names for x and y aesthetics are typically omitted because
27
- # ' they are so common; all other aesthetics must be named.
25
+ # ' @param x,y,... List of name-value pairs in the form `aesthetic = column_name`
26
+ # ' describing which variables in the layer data should be mapped to which
27
+ # ' aesthetics used by paired geom/stat. The names for x and y aesthetics are typically
28
+ # ' omitted because they are so common; all other aesthetics must be named.
28
29
# ' @seealso [vars()] for another quoting function designed for
29
30
# ' faceting specifications.
30
31
# ' @return A list with class `uneval`. Components of the list are either
@@ -344,30 +345,28 @@ mapped_aesthetics <- function(x) {
344
345
# ' @param data The data to be mapped from
345
346
# '
346
347
# ' @noRd
347
- check_aes_extract_usage <- function (mapping , data ) {
348
- lapply(mapping , check_aes_extract_usage_quo , data )
349
- }
350
-
351
- check_aes_extract_usage_quo <- function (quosure , data ) {
352
- check_aes_extract_usage_expr(get_expr(quosure ), data , get_env(quosure ))
348
+ warn_for_aes_extract_usage <- function (mapping , data ) {
349
+ lapply(mapping , function (quosure ) {
350
+ warn_for_aes_extract_usage_expr(get_expr(quosure ), data , get_env(quosure ))
351
+ })
353
352
}
354
353
355
- check_aes_extract_usage_expr <- function (x , data , env = emptyenv()) {
354
+ warn_for_aes_extract_usage_expr <- function (x , data , env = emptyenv()) {
356
355
if (is_call(x , " [[" ) || is_call(x , " $" )) {
357
- if (extract_target_is_data (x , data , env )) {
358
- good_usage <- check_aes_get_alternative_usage (x )
356
+ if (extract_target_is_likely_data (x , data , env )) {
357
+ good_usage <- alternative_aes_extract_usage (x )
359
358
warning(
360
359
" Use of `" , format(x ), " ` is discouraged. " ,
361
360
" Use `" , good_usage , " ` instead." ,
362
361
call. = FALSE
363
362
)
364
363
}
365
364
} else if (is.call(x )) {
366
- lapply(x , check_aes_extract_usage_expr , data , env )
365
+ lapply(x , warn_for_aes_extract_usage_expr , data , env )
367
366
}
368
367
}
369
368
370
- check_aes_get_alternative_usage <- function (x ) {
369
+ alternative_aes_extract_usage <- function (x ) {
371
370
if (is_call(x , " [[" )) {
372
371
good_call <- call2(" [[" , quote(.data ), x [[3 ]])
373
372
format(good_call )
@@ -378,7 +377,13 @@ check_aes_get_alternative_usage <- function(x) {
378
377
}
379
378
}
380
379
381
- extract_target_is_data <- function (x , data , env ) {
382
- data_eval <- try(eval_tidy(x [[2 ]], data , env ), silent = TRUE )
383
- identical(data_eval , data )
380
+ extract_target_is_likely_data <- function (x , data , env ) {
381
+ if (! is.name(x [[2 ]])) {
382
+ return (FALSE )
383
+ }
384
+
385
+ tryCatch({
386
+ data_eval <- eval_tidy(x [[2 ]], data , env )
387
+ identical(data_eval , data )
388
+ }, error = function (err ) FALSE )
384
389
}
0 commit comments