ifelse cannot return invisible(NULL), so the workaround is more cumbersome