Single if without else

When you use the single argument form without an else statement, if invisibly (Section 6.7.2) returns NULL if the condition is FALSE. Since functions like c() and paste() drop NULL inputs, this allows for a compact expression of certain idioms:

greet <- function(name, birthday = FALSE) {
  paste0(
    "Hi ", name,
    if (birthday) " and HAPPY BIRTHDAY"
  )
}
greet("Maria", FALSE)
#> [1] "Hi Maria"
greet("Jaime", TRUE)
#> [1] "Hi Jaime and HAPPY BIRTHDAY"
format_lane_text <- function(number){

  paste0(
    number,
    " lane",
    if (number > 1) "s",
    " of sequencing"
  )
}

format_lane_text(1)
#> [1] "1 lane of sequencing"
format_lane_text(4)
#> [1] "4 lanes of sequencing"