# NOT RUN {
##
## 1. name in object, return
##
e1 <- getElement2(list(ab=1), 'ab', 2) # 1
# check
# }
# NOT RUN {
all.equal(e1, 1)
# }
# NOT RUN {
##
## 2. name not in object, return default
##
eNA <- getElement2(list(), 'ab') # default default = NA
# check
# }
# NOT RUN {
all.equal(eNA, NA)
# }
# NOT RUN {
e0 <- getElement2(list(), 'ab', 2) # name not in object
# }
# NOT RUN {
all.equal(e0, 2)
# }
# NOT RUN {
e2 <- getElement2(list(ab=1), 'a', 2) # partial matching not used
# }
# NOT RUN {
all.equal(e2, 2)
# }
# NOT RUN {
##
## 3. name NULL in object, return default
##
ed <- getElement2(list(a=NULL), 'a',2) # 2 with a warning
# }
# NOT RUN {
all.equal(ed, 2)
# }
# NOT RUN {
e. <- getElement2(list(a=NULL), 'a', 2, warn.NULL=FALSE) # NULL
# }
# NOT RUN {
all.equal(e., NULL)
# }
# NOT RUN {
eNULL <- getElement2(list(a=NULL), 'a', NULL) # NULL
# }
# NOT RUN {
all.equal(eNULL, NULL)
# }
# NOT RUN {
##
## 4. Language: find, eval, return
##
Qte <- quote(plot(1:4, y=x, col=c2))
if(require(pryr)){
Qt <- pryr::standardise_call(Qte) # add the name 'x'
fn <- getElement2(Qt)
eQuote <- getElement2(Qt, 'y')
Col2 <- getElement2(Qt, 'col', envir=list(c2=2))
# check
# }
# NOT RUN {
all.equal(fn, 'plot')
# }
# NOT RUN {
all.equal(eQuote, 1:4)
# }
# NOT RUN {
all.equal(Col2, 2)
# }
# NOT RUN {
}
# }
Run the code above in your browser using DataLab