op-empty-default: Replace an empty vector with something else.

Description Usage Arguments Examples

Description

Based on '%||%' from rlang.

Usage

1
x %|||% y

Arguments

x, y

if 'x' is empty, will return 'y'; otherwise returns 'x'.

Examples

1
2
3
4
5
6
7
8
9
c(1, 2)[1] %|||% NA_real_
c(1, 2)[0] %|||% NA_real_

df <- data.frame(
  name   = c("a",   "a", "b", "c", "c", "a", "a"),
  var    = c("hgt", "wt", "hgt", "wt", "hgt", "eye", "wt"),
  value  = c(72, 225, 64, 60, 142, 2, 210)
)
df$value[df$name == "b" & df$var == "wt"] %|||% NA_real_

jalsalam/JRAtools documentation built on May 10, 2019, 1:16 p.m.