DataExplorer icon indicating copy to clipboard operation
DataExplorer copied to clipboard

plot_qq throws Error in `combine_vars()`: ! Faceting variables must have at least one value

Open kosalk opened this issue 3 years ago • 1 comments

When calling plot_qq with a "by" parameter, an error is thrown: Error in combine_vars(): ! Faceting variables must have at least one value

While debugging, it appears that error happens in this precise case:

  • the number of continuous variables is such that there remains 1 plot in the last page; e.g. 217 continuous variables for a 3x3 page => 24 pages with 9 plots each + 1 page with 1 plot
  • the "by" parameter is among the continuous variables, it is removed from dt2, so only N-1 variables are plotted => the last page is empty!
  • when trying to plot the last page, the error is thrown.

Solution: In plot_qq, check that "by" is not among the continuous variables: nplots <- ncol(continuous) if (!is.null(by) && by %in% names(split_obj$continuous)) nplots <- nplots - 1 layout <- .getPageLayout(nrow, ncol, nplots)

kosalk avatar Sep 07 '22 18:09 kosalk

Can reproduce with a simpler example:

library(DataExplorer)
library(data.table)

test <- data.table(sapply(seq.int(3L), function(x) rnorm(100L)))
plot_qq(test, by = "V1", nrow = 1L, ncol = 2L)

As OP mentioned, variable in by is getting through and being removed at the same time.

Plot is still being generated, but with a blank page and an error message. To suppress the error, do:

try(plot_qq(test, by = "V1", nrow = 1L, ncol = 2L), silent = TRUE)

boxuancui avatar Sep 07 '22 18:09 boxuancui