Skip to content

Commit

Permalink
Export %||%
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Nov 11, 2015
1 parent 4133c8b commit 9b1c44b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export("%||%")
export(array_branch)
export(array_tree)
export(as_function)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Expand Up @@ -19,3 +19,5 @@

* `list_along()` and `rep_along()` generalise the idea of `seq_along().
(#122).

* `%||%` is now exported (#109).
17 changes: 15 additions & 2 deletions R/utils.R
Expand Up @@ -95,8 +95,21 @@ names2 <- function(x) {
names(x) %||% rep("", length(x))
}

"%||%" <- function(x, y) {
if(is.null(x)) {
#' Default value for \code{NULL}.
#'
#' This infix function makes it easy to replace \code{NULL}s with a
#' default value. It's inspired by the way that Ruby's or operation (\code{||})
#' works.
#'
#' @param x,y If \code{x} is NULL, will return \code{y}; otherwise returns
#' \code{x}.
#' @export
#' @name null-default
#' @examples
#' 1 %||% 2
#' NULL %||% 2
`%||%` <- function(x, y) {
if (is.null(x)) {
y
} else {
x
Expand Down
23 changes: 23 additions & 0 deletions man/null-default.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9b1c44b

Please sign in to comment.