Skip to content

Commit

Permalink
Restrict automatic plot variable selection to numeric variables
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchelloharawild committed Jan 11, 2021
1 parent 338b364 commit 5551f01
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ autoplot.tbl_ts <- function(object, .vars = NULL, ...){
nk <- n_keys(object)

if(quo_is_null(quo_vars)){
if(is_empty(measured_vars(object))){
abort("There are no variables to plot.")
mv <- measured_vars(object)
pos <- which(vapply(object[mv], is.numeric, logical(1L)))
if(is_empty(pos)) {
abort("Could not automatically identify an appropriate plot variable, please specify the variable to plot.")
}
inform(sprintf(
"Plot variable not specified, automatically selected `.vars = %s`",
measured_vars(object)[1]
mv[pos[1]]
))
y <- sym(measured_vars(object)[1])
y <- sym(mv[pos[1]])
.vars <- as_quosures(list(y), env = empty_env())
}
else if(possibly(compose(is_quosures, eval_tidy), FALSE)(.vars)){
Expand Down Expand Up @@ -83,14 +85,16 @@ autolayer.tbl_ts <- function(object, .vars = NULL, ...){
nk <- n_keys(object)

if(quo_is_null(quo_vars)){
if(is_empty(measured_vars(object))){
abort("There are no variables to plot.")
mv <- measured_vars(object)
pos <- which(vapply(object[mv], is.numeric, logical(1L)))
if(is_empty(pos)) {
abort("Could not automatically identify an appropriate plot variable, please specify the variable to plot.")
}
inform(sprintf(
"Plot variable not specified, automatically selected `.vars = %s`",
measured_vars(object)[1]
mv[pos[1]]
))
y <- sym(measured_vars(object)[1])
y <- sym(mv[pos[1]])
.vars <- as_quosures(list(y), env = empty_env())
}
else if(possibly(compose(is_quosures, eval_tidy), FALSE)(.vars)){
Expand Down

0 comments on commit 5551f01

Please sign in to comment.