Skip to content

Instantly share code, notes, and snippets.

@danielecook
Last active April 24, 2020 01:31
Show Gist options
  • Save danielecook/b3efe94bb26d9703316160fbbac4e3e2 to your computer and use it in GitHub Desktop.
Save danielecook/b3efe94bb26d9703316160fbbac4e3e2 to your computer and use it in GitHub Desktop.
II, I, &&, & Operators in R
# A double bar || OR in R "short circuits"
# The || operator will skip evaluating the second argument if the first argument is TRUE.
{ print("left"); TRUE } || { print("right"); TRUE } # Prints left
{ print("left"); FALSE } || { print("right"); TRUE } # Prints left, right
# The && operator will skip evaluating the second argument if the first argument is TRUE.
{ print("left"); TRUE } && { print("right"); TRUE } # Prints left, right
{ print("left"); FALSE } && { print("right"); TRUE } # Prints right
# Both arguments will be evaluated, even though the first one is TRUE
{ print("left"); TRUE } | { print("right"); FALSE }
# Both arguments will be evaluated, even though the first one is FALSE:
{ print("left"); FALSE } & { print("right"); FALSE }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment