Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does %||% do in R?

Tags:

r

I am trying to run some R code from github, however these functions use a command %||%, that doesn't seem to be in base R. What exactly does this function do and what packages, if any, do I need to get it to work on my machine? As you can imagine, this particular string is un-Google-able since it's entirely special characters.

like image 915
Jacqueline Nolis Avatar asked Jun 12 '14 17:06

Jacqueline Nolis


1 Answers

From https://github.com/hadley/devtools/blob/master/R/utils.r

"%||%" <- function(a, b) if (!is.null(a)) a else b

It's an internal function, so you probably need to redefine it for yourself if you want to use it outside the package.

"%||%" <- devtools:::`%||%`
1 %||% NULL
## [1] 1
NULL %||% 2
## [1] 2
like image 189
Ben Bolker Avatar answered Nov 15 '22 06:11

Ben Bolker