yanlinlin82 / ggvenn

Venn Diagram by ggplot2, with really easy-to-use API.
Other
167 stars 25 forks source link

Better error reporting for wrong values passed in show_elements #22

Closed konradzdeb closed 2 years ago

konradzdeb commented 3 years ago

Problem

The code:

 d <- tibble(value   = c(1,     2,     3,     5,     6,     7,     8,     9),
             `Set 1` = c(TRUE,  FALSE, TRUE,  TRUE,  FALSE, TRUE,  FALSE, TRUE),
             `Set 2` = c(TRUE,  FALSE, FALSE, TRUE,  FALSE, FALSE, FALSE, TRUE),
             `Set 3` = c(TRUE,  TRUE,  FALSE, FALSE, FALSE, FALSE, TRUE,  TRUE),
             `Set 4` = c(FALSE, FALSE, FALSE, FALSE, TRUE,  TRUE,  FALSE, FALSE))
ggvenn(d, c("Set 1", "Set 2"), show_elements = TRUE)

Would return error message reflecting is.character call evaluating to FALSE in stopifnot. stopifnot is only a convenience function for call:

if(!all(conditions)) stop(any message)

receiving notification that is.character returns FALSE the user could be tempted to run

ggvenn(d, c("Set 1", "Set 2"), show_elements = "TRUE")

This is unhelpful as the real problem is associated with the value not corresponding to the data frame column.

Desired behaviour

Informative error message leading to solution irrespectively of whether failure happened at is.character or later

Proposed fix

Evaluate the required condition and then return consistent, informative error message.


For a more robust argument checking the `checkmate' provides a better well-painted alternative.

yanlinlin82 commented 2 years ago

Hi @konradzdeb,

Thank you for your contribution, and I am very sorry for the too late response.