@@ -290,10 +290,7 @@ as_facets_list <- function(x) {
290
290
# facet_wrap() called as.quoted(). Hence this is a little more
291
291
# complicated for backward compatibility.
292
292
if (rlang :: is_string(x )) {
293
- x <- plyr :: as.quoted(x )
294
- if (rlang :: is_formula(x [[1 ]])) {
295
- x <- x [[1 ]]
296
- }
293
+ x <- rlang :: parse_expr(x )
297
294
}
298
295
299
296
# At this level formulas are coerced to lists of lists for backward
@@ -306,13 +303,12 @@ as_facets_list <- function(x) {
306
303
307
304
# For backward-compatibility with facet_wrap()
308
305
if (! rlang :: is_bare_list(x )) {
309
- x <- plyr :: as.quoted(x )
310
- attributes(x ) <- NULL
306
+ x <- as_quoted(x )
311
307
}
312
308
313
309
# If we have a list there are two possibilities. We may already have
314
310
# a proper facet spec structure. Otherwise we coerce each element
315
- # with plyr::as.quoted () for backward compatibility with facet_grid().
311
+ # with as_quoted () for backward compatibility with facet_grid().
316
312
if (is.list(x )) {
317
313
x <- lapply(x , as_facets )
318
314
}
@@ -324,6 +320,38 @@ as_facets_list <- function(x) {
324
320
x
325
321
}
326
322
323
+ # Compatibility with plyr::as.quoted()
324
+ as_quoted <- function (x ) {
325
+ if (is.character(x )) {
326
+ return (rlang :: parse_exprs(x ))
327
+ }
328
+ if (is.null(x )) {
329
+ return (list ())
330
+ }
331
+ if (rlang :: is_formula(x )) {
332
+ return (simplify(x ))
333
+ }
334
+ list (x )
335
+ }
336
+ # From plyr:::as.quoted.formula
337
+ simplify <- function (x ) {
338
+ if (length(x ) == 2 && rlang :: is_symbol(x [[1 ]], " ~" )) {
339
+ return (simplify(x [[2 ]]))
340
+ }
341
+ if (length(x ) < 3 ) {
342
+ return (list (x ))
343
+ }
344
+ op <- x [[1 ]]; a <- x [[2 ]]; b <- x [[3 ]]
345
+
346
+ if (rlang :: is_symbol(op , c(" +" , " *" , " ~" ))) {
347
+ c(simplify(a ), simplify(b ))
348
+ } else if (rlang :: is_symbol(op , " -" )) {
349
+ c(simplify(a ), expr(- !! simplify(b )))
350
+ } else {
351
+ list (x )
352
+ }
353
+ }
354
+
327
355
f_as_facets_list <- function (f ) {
328
356
lhs <- function (x ) if (length(x ) == 2 ) NULL else x [- 3 ]
329
357
rhs <- function (x ) if (length(x ) == 2 ) x else x [- 2 ]
@@ -352,7 +380,7 @@ as_facets <- function(x) {
352
380
# environment correctly.
353
381
f_as_facets(x )
354
382
} else {
355
- vars <- plyr :: as.quoted (x )
383
+ vars <- as_quoted (x )
356
384
rlang :: as_quosures(vars , globalenv(), named = TRUE )
357
385
}
358
386
}
0 commit comments