Description Usage Arguments Value Author(s) Examples
This is a C like ternary operator, the syntax being
condition %?% true %:% false
.
1 2 3 | condition %?% true
lhs %:% false
|
condition |
logical. A vector. |
true, false |
Values to use for |
lhs |
Left-hand side of |
If length(x) > 1
, then ifelse
is used.
Richie Cotton, see https://stackoverflow.com/a/8791496/3902976; Paul Poncet for the small modifications introduced.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | (capitalize <- sample(c(TRUE, FALSE), 1))
capitalize %?% LETTERS[1:3] %:% letters[1:2]
# Does not work
## Not run:
capitalize %?% 1*1:3 %:% 1:2
## End(Not run)
# Does work
capitalize %?% {1*1:3} %:% 1:2
# Does work too
capitalize %?% (1*1:3) %:% 1:2
# Vectorized version also works
c(capitalize,!capitalize) %?% "A" %:% c("b","c")
# Chaining operators is permitted
FALSE %?% "a" %:%
(FALSE %?% "b") %:%
(capitalize %?% "C") %:% "c"
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.