UpSetR
UpSetR copied to clipboard
Handling of queries with no data
Hi,
Is there an optimal approach to handling the scenario where an UpSetR query may have no data to work with. For instance:
library("UpSetR")
movies <-
read.csv(
system.file("extdata", "movies.csv", package = "UpSetR"),
header = T, sep = ";"
)
# Example query taken from https://cran.r-project.org/web/packages/UpSetR/vignettes/queries.html
Myfunc <- function(row, release, rating) {
data <- (row["ReleaseDate"] %in% release) & (row["AvgRating"] > rating)
}
valid_release <- c(1970, 1980, 1990, 1999, 2000)
upset(
movies,
queries =
list(
list(
query = Myfunc,
params = list(valid_release, 2.5),
color = "blue",
active = T
)
)
)
But when you give it a filter that returns no data:
invalid_release <- 3000
upset(
movies,
queries =
list(
list(
query = Myfunc,
params = list(invalid_release, 2.5),
color = "blue",
active = T
)
)
)
#> Error in `$<-.data.frame`(`*tmp*`, "color", value = "blue"): replacement has 1 row, data has 0
This fails because there are no movies released in 3000. What I would like is to have a generic UpSet function that could handle different scenarios. Was just wondering if there is an optimal way to do?
> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin16.7.0 (64-bit)
Running under: macOS Sierra 10.12.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libLAPACK.dylib
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] reprex_0.2.1 UpSetR_1.3.3 nvimcom_0.9-74 colorout_1.2-0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.19 pillar_1.3.0 compiler_3.5.1 plyr_1.8.4 bindr_0.1.1 base64enc_0.1-3 tools_3.5.1 digest_0.6.18 evaluate_0.12 tibble_1.4.2 gtable_0.2.0 pkgconfig_2.0.2 rlang_0.3.0.1 bindrcpp_0.2.2 gridExtra_2.3
[16] dplyr_0.7.7 knitr_1.20 fs_1.2.6 rprojroot_1.3-2 grid_3.5.1 tidyselect_0.2.5 glue_1.3.0 R6_2.3.0 processx_3.2.0 rmarkdown_1.10 ggplot2_3.1.0 purrr_0.2.5 callr_3.0.0 clipr_0.4.1 magrittr_1.5
[31] whisker_0.3-2 ps_1.2.0 backports_1.1.2 scales_1.0.0 htmltools_0.3.6 assertthat_0.2.0 colorspace_1.3-2 labeling_0.3 lazyeval_0.2.1 munsell_0.5.0 crayon_1.3.4
@tinyheero did you manage to find a work around? I'm having similar trouble.