grapes-set-help-grapes: Right-hand side checked assignment Provides a way to avoid...

Description Usage Arguments Value Examples

Description

Right-hand side checked assignment Provides a way to avoid assignment to the left-hand side. If the statement 'value' is invalid or NULL, this function will not assign values and nothing happens.

Usage

1
lhs %<-?% value

Arguments

lhs

an object to be assigned to

value

value to be checked

Value

Assign value on the right-hand side to the left-hand side if value does exists and is not NULL

Examples

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

# aaa will not be assigned. run `print(aaa)` will raise error
aaa %<-?% NULL

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

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

dipsaus documentation built on Oct. 13, 2021, 5:07 p.m.