getNestedClass: Get Class of Nested Object (generic)

Description Usage Arguments Path-like identifiers Author(s) References See Also Examples

Description

Retrieves the class of a component inside a nested object structure based on a path-like id with the last ID component being the actual object name that is looked up.

Usage

1
2
getNestedClass(id, where = parent.frame(), default = NULL, strict = c(0,
  1, 2), ...)

Arguments

id

Signature argument. Object containing path-like name/ID information.

where

Signature argument. Object containing location information.

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.

Path-like identifiers

Values for id are expected to be of structure a/b/c/.../z, i.e. path-like identifiers using a slash as separator. The identifier is transformed to a$b$c$...$z and then in turn to a valid get or assign expression (i.e. a$b$c$...$z and a$b$c$...$z <- value). Of course, "atomic" paths (e.g. only a) are also valid.

Author(s)

Janko Thyson [email protected]

References

http://github.com/Rappster/nestr

See Also

getNestedClass-char-env-method, setNested, getNested, existsNested, rmNested

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
## Not run: 

##------------------------------------------------------------------------------
## Basics //
##------------------------------------------------------------------------------

setNested(id = "test", value = TRUE)
getNestedClass(id = "test")

setNested(id = "a/b/c", value = 10)
getNestedClass(id = "a")
getNestedClass(id = "a/b")
getNestedClass(id = "a/b/c")
getNestedClass(id = "a/b/c/d")

getNestedClass(id = "c")
getNestedClass(id = "c/d/e")
  
##------------------------------------------------------------------------------
## Strictness levels //
##------------------------------------------------------------------------------

## Empty ID //
getNestedClass(id = character())
try(getNestedClass(id = character(), strict = 1))
try(getNestedClass(id = character(), strict = 2))

## Not-existing //  
getNestedClass(id = "c/d/e")
try(getNestedClass(id = "c/d/e", strict = 1))
try(getNestedClass(id = "c/d/e", strict = 2))

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

where <- new.env()
setNested(id = "a/b/c", value = 10, where = where)
getNestedClass(id = "a/b/c", where = where)
getNestedClass(id = "a/b/c/d", where = where)
getNestedClass(id = "c/d/e", where = where)


## End(Not run)

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