eget

0th

Percentile

Gets a variable by name

Gets a variable by name. If non-existing, the default value is returned.

Keywords
internal, file, IO
Usage
eget(..., coerce=TRUE, envir=parent.frame(), inherits=FALSE, mode="default",
  cmdArg=FALSE)
Arguments
...

Named arguments name and default, where name must be a character string and default is an optional default value (if not given, it's NULL). Alternatively, name and default can be given as a named argument (e.g. n=42).

coerce

If TRUE, the returned value is coerced to the class of the default value (unless NULL) using as.

envir

A environment or a named list where to look for the variable. Only if envir is an environment.

inherits

A logical specifying whether the enclosing frames of the environment should be searched or not.

mode

A character string specifying the mode of the object to retrieve. Only if envir is an environment.

cmdArg

If TRUE, the corresponding command-line argument is used as the default value.

Details

ecget(...) is short for eget(..., cmdArg=TRUE).

Value

Returns an object.

See Also

To retrieve command-line arguments, see cmdArg. See also mget().

Aliases
  • eget
  • ecget
Examples
# NOT RUN {
# Get variable 'a' if it exists, otherwise return the default value.
value <- eget("a", default=42L)
print(value) # 42L

# Short version doing the same
value <- eget(a=42L)
print(value) # 42L

# Same, but look for the variable in 'envir' (here a list)
value <- eget("a", default=42L, envir=list(a=1))
print(value) # 1L

# Get variable 'n', which defaults to command-line argument
# 'n' ('-n' or '--n'), which in turn defaults to 42L.
value <- eget(n=cmdArg(n=42L))
print(value)

# Equivalently.
value <- ecget(n=42L)
print(value)
# }
Documentation reproduced from package R.utils, version 2.8.0, License: LGPL (>= 2.1)

Community examples

Looks like there are no examples yet.