Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment outside of if #131

Open
hadley opened this issue Oct 13, 2021 · 1 comment
Open

Assignment outside of if #131

hadley opened this issue Oct 13, 2021 · 1 comment

Comments

@hadley
Copy link
Member

hadley commented Oct 13, 2021

  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?

@jennybc
Copy link
Member

jennybc commented Oct 13, 2021

Related to #71

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants