rlist (version 0.4.6.1)

tryGet: Try to get the value of a symbol if exists or return a default value

Description

Try to get the value of a symbol if exists or return a default value

Usage

tryGet(symbol, def = NULL, ..., envir = parent.frame())

Arguments

symbol

the symbol to examine

def

the default value if the symbol does not exist

...

additional parameters passed to exists and get

envir

the environment to examine whether the symbol exists and get the symbol

Details

By default, the symbol is examined in envir without inheritance, that is, if the symbol does not exist in envir the default value def will be returned.

Examples

Run this code
# NOT RUN {
x <- list(a=c(x=1,y=2),b=c(x=2,p=3))
list.map(x, tryGet(y,0))
# }

Run the code above in your browser using DataCamp Workspace