R will plot the Venn diagrams and shaded areas correctly, but it will not say A or A' in the console. The image below is an example of what I'm trying to have done. Note that the function "venn" is used from the "venn" package: https://cran.r-project.org/web/packages/venn/venn.pdf
Example of preferred output in the console
genvd = function(x){
x = venn(x,zcolor = "blue",ilabels = F)
if (x == "A") {
print("A",quote = FALSE)
return(x)
}
else if (x == "~A") {
print("A'",quote = FALSE)
return(x)
}
}
genvd("A")
genvd("~A")
Error Code:
Error in if (x == "A") { : argument is of length zero
CodePudding user response:
The error comes from the usage of condition on the venn
object instead of the original input. We could assign it to a new object. In addition, print
doesn't have any return value.
genvd <- function(x){
venn::venn(x,zcolor = "blue",ilabels = FALSE)
if (x == "A") {
print("A",quote = FALSE)
}
else if (x == "~A") {
print("A'",quote = FALSE)
}
}
The venn
object is not returning anything
> tmp <- venn("A", zcolor = "blue", ilabels = FALSE)
> str(tmp)
NULL
-testing
> genvd("A")
[1] A
> genvd("~A")
[1] A'