getNested-character-environment-method: Get Nested (char-env)

Description Usage Arguments Value Author(s) References See Also Examples

Description

See generic: getNested

Usage

1
2
3
## S4 method for signature 'character,environment'
getNested(id, where = parent.frame(),
  default = NULL, strict = c(0, 1, 2), ...)

Arguments

id

character.

where

environment.

default

ANY. Value to be returned if component does not exist.

strict

logical. Controls what happens when id points to a non-existing component:

  • 0: ignore and return FALSE to signal that the assignment process was not successful or fail_value depending on the value of return_status

  • 1: ignore and with warning and return FALSE

  • 2: ignore and with error

...

Further arguments to be passed to subsequent functions/methods.

Value

ANY. Component value or for invalid argument input and non-existing component the value of default unless strict == 1 in which case a warning is issued or strict == 2 in which case an error is thrown.

Author(s)

Janko Thyson [email protected]

References

http://github.com/Rappster/nestr

See Also

getNested

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
## Not run: 

## Also see examples at `?setNested`
  
##------------------------------------------------------------------------------
## Basics //
##------------------------------------------------------------------------------

setNested(id = "test", value = TRUE)
getNested(id = "test")
## --> leaf

setNested(id = "a/b/c", value = 10, gap = TRUE)
ls(getNested(id = "a"))
## --> branch
ls(getNested(id = "a/b"))
## --> branch
getNested(id = "a/b/c")
## --> leaf
  
## Clean up //
rm(test)
rm(a)

##------------------------------------------------------------------------------
## Explicit `where` //
##------------------------------------------------------------------------------

where <- new.env()
setNested(id = "a/b/c", value = 10, where = where, gap = TRUE)
getNested(id = "a/b/c", where = where)

## Clean up //
rm(where)

##------------------------------------------------------------------------------
## Different `default` //
##------------------------------------------------------------------------------

setNested(id = "test", value = 10)
getNested(id = "test", default = NA)
getNested(id = "z", default = NA)
getNested(id = "z/a/b", default = NA)

getNested(id = "test", default = "nope")
getNested(id = "z", default = "nope")
getNested(id = "z/a/b", default = "nope")

## Clean up //
rm(test)


## End(Not run)

rappster/nestr documentation built on May 24, 2017, 7:33 p.m.