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

Description Usage Arguments Details Examples

View source: R/utils.R

Description

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

Usage

1
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

1
2
x <- list(a=c(x=1,y=2),b=c(x=2,p=3))
list.map(x, tryGet(y,0))

Example output

$a
[1] 2

$b
[1] 0

rlist documentation built on Sept. 5, 2021, 5:30 p.m.