A Ternary Conditional Operator for R




R-CMD-check Codecov test coverage


rtern brings a conditional ternary operator using ? and : to R.

This groundbreaking spoonful of syntactic sugar will supercharge your workflow and see you bubble to the top of Kaggle leaderboards.

Yes, we know that it is possible to perform conditional assignment in base R multiple ways:

x <- if(y > 1) 1 else 2
# vectorized form:
x <- ifelse(y > 1, 1, 2)

However we're sure you'll agree that once you can do the same using only...

x <- y > 1 ? 1 : 2

...your models will converge faster, ROC AUC will approach 1 and Hadley Wickham will be starring your repos.

The only downsides are that your linter won't like it and that this masks the base functionality of ? in R .
As of v0.1 help files can still be accessed by the ? operator whilst rtern is attached!

Who needs help files? Not you, champ.


rtern is a lighthearted project for practicing package development and nonstandard evaluation in R. The ? operator implementation borrows heavily from this Stack Exchange answer.


You can install the latest released version of rtern from CRAN with:


Or install the development version from GitHub with:

# install.packages("devtools")