grapes-help-set-grapes: Left-hand side checked assignment Provides a way to assign...

Description Usage Arguments Value Examples

Description

Left-hand side checked assignment Provides a way to assign default values to variables. If the statement 'lhs' is invalid or NULL, this function will try to assign value, otherwise nothing happens.

Usage

1
lhs %?<-% value

Arguments

lhs

an object to check or assign

value

value to be assigned if lhs is NULL

Value

Assign value on the right-hand side to the left-hand side if lhs does not exist or is NULL

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# Prepare, remove aaa if exists
if(exists('aaa', envir = globalenv(), inherits = FALSE)){
  rm(aaa, envir = globalenv())
}

# Assign
aaa %?<-% 1; print(aaa)

# However, if assigned, nothing happens
aaa = 1;
aaa %?<-% 2;
print(aaa)

# in a list
a = list()
a$e %?<-% 1; print(a$e)
a$e %?<-% 2; print(a$e)

dipsaus documentation built on Sept. 6, 2021, 5:08 p.m.