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.
Source: R/language.R
grapes-set-help-grapes.Rd
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.
Value
Assign value on the right-hand side to the left-hand side if
value
does exists and is not NULL
Examples
# 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)
#> [1] 1
# in a list
a = list()
a$e %<-?% bbb; print(a$e)
#> NULL
a$e %<-?% 2; print(a$e)
#> [1] 2