Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What does the %||% expression do in R

I am working with some Code containing the expression %||%.

This is the context i encountered it:

# Example list for minimal example 
df <- list(a=1,2,c=3)
# code
ind <- names(df) %||% seq_along(df)

But R cannot find the operator %||%. I guess a package is not installed but i do not know which one. I also cannot find it on google or stackoverflow.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Could someone explain what it does and which package it belongs to?

>Solution :

It’s from ggplot2 utilities.

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

You can find in utilities.r

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading