Search code examples
rvenn-diagram

Empty sets in VennDiagram result in error


I have the following Script for R - VennDiagram, where the sets are filled automatically and where sets (like here b1) may be empty:

suppressPackageStartupMessages(library(VennDiagram))
b1 <- c()
b2 <- c(1,2)
base_data <- list(b1, b2)
names(base_data) <- c("b1", "b2")
pdf(file="out.pdf",7,7)
p1 <- venn.diagram(base_data,filename = NULL,euler.d=False,cex=2,cat.cex=2)
grid.draw(p1)
dev.off()

R than gives me the following error:

Error in x[[i]] : subscript out of bounds
Calls: venn.diagram -> unique
Execution halted

I tested several variants and it is always thrown, as long as in the created list an empty set is in front of another set.

I know that for other R-Venn libraries it is even possible to pass 4 empty sets and resolve a Venn diagram filled with zero in each section.

So, is VennDiagram able to build a diagram out of empty sets, too? And if yes, what am I doing wrong?

Thank you in advance!

Julia


Solution

  • Well, let me point out that the empty set is not really a valid item to put into a Venn (or Euler) diagram, so you should not try to do so. Does the intersection of the empty set with anything have any elements? (no).

    If other packages are drawing empty sets, then they are violating the rules of algebra. As a final example, try comparing the intersection of two empty sets with the union of the same two empty sets.