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.
Source: R/language.R
grapes-help-set-grapes.Rd
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.
Examples
# Prepare, remove aaa if exists
if(exists('aaa', envir = globalenv(), inherits = FALSE)){
rm(aaa, envir = globalenv())
}
# Assign
aaa %?<-% 1; print(aaa)
#> [1] 1
# However, if assigned, nothing happens
aaa = 1;
aaa %?<-% 2;
print(aaa)
#> [1] 1
# in a list
a = list()
a$e %?<-% 1; print(a$e)
#> [1] 1
a$e %?<-% 2; print(a$e)
#> [1] 1