5

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.

Jacqueline Nolis
  • 1,457
  • 15
  • 22
  • 3
    usually seen it defined as an analogue to the ruby `||` operator, as in [hadley's ggplot code](https://github.com/hadley/ggplot2/blob/master/R/utilities.r#L1:L9) – rawr Jun 12 '14 at 17:45

1 Answers1

10

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
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453