Assignment outside of if
hadley opened this issue · 1 comments
hadley commented
if (is.null(version_label)) {
version_label <- if (mode %in% c("release", "default")) {
if (bs_version == 3) {
"default"
} else {
"info"
}
} else {
"danger"
}
}
I rewrote to
if (is.null(version_label)) {
if (mode %in% c("release", "default")) {
version_label <- if (bs_version == 3) "default" else "info"
} else {
version_label <- "danger"
}
}
If you wanted to keep the exterior assignment, I'd write a helper function:
version_label <- function(mode, bs_version) {
if (mode %in% c("release", "default")) {
if (bs_version == 3) {
"default"
} else {
"info"
}
} else {
"danger"
}
}
version_label <- version_label %||% version_label(mode, bs_version)
Maybe with different name?