Last active
April 24, 2020 01:31
-
-
Save danielecook/b3efe94bb26d9703316160fbbac4e3e2 to your computer and use it in GitHub Desktop.
II, I, &&, & Operators in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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