%?<-% | R Documentation |
lhs
' is invalid or NULL
, this function will try to assign
value
, otherwise nothing happens.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.
lhs %?<-% value
lhs |
an object to check or assign |
value |
value to be assigned if lhs is NULL |
Assign value on the right-hand side to the left-hand side if
lhs
does not exist or is NULL
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.